diff options
Diffstat (limited to 'docs/std')
| -rw-r--r-- | docs/std/string.md | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/docs/std/string.md b/docs/std/string.md index ae4b738..1f89e0f 100644 --- a/docs/std/string.md +++ b/docs/std/string.md @@ -9,14 +9,22 @@ import "std/string.zc" fn main() { let s = String::from("Hello"); - s.append(String::from(" World")); + // Ensure memory is freed + defer { s.free(); } + + // Append requires a pointer to another String + let part = String::from(" World"); + defer { part.free(); } + + s.append(&part); - println "{s}"; // Prints "Hello World" + // Use c_str() to print + println "{s.c_str()}"; // Prints "Hello World" if (s.starts_with("Hello")) { // ... } -} // s is freed automatically +} ``` ## Structure |
