added string.replace
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 26 Oct 2021 13:08:45 +0000 (08:08 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 26 Oct 2021 13:08:45 +0000 (08:08 -0500)
core/string.onyx

index aa639618e9f0f9319cae3229541bda0d2a197759..9b6da85d47c1cf30b9eb9bc6efe9cd348a6d86e4 100644 (file)
@@ -261,6 +261,12 @@ advance :: #match {
     }
 }
 
+replace :: (s: str, to_replace: u8, replace_with: u8) {
+    for ^c: str {
+        if *c == to_replace do *c = replace_with;
+    }
+}
+
 read_until :: (s: ^str, upto: u8, skip := 0) -> str {
     if s.count == 0 do return "";