From 270eea5e23e3aeaa93aa0b483cba76cfee1f0df9 Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Tue, 27 Jan 2026 10:29:20 +0000 Subject: Related to #133 --- docs/std/string.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'docs/std') 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 -- cgit v1.2.3