Each returns a new string (string is an immutable value type). index is a byte
offset, matching char_at. A char argument is a codepoint and is UTF-8 encoded into the
result.
Function
Signature
Description
append_char
(s string, c char) -> string
New string with c added at the end
prepend_char
(s string, c char) -> string
New string with c added at the front
insert_char_at
(s string, index i64, c char) -> string
New string with c inserted at byte index; index == len appends; panics if index < 0 or index > len
remove_at
(s string, index i64) -> string
New string with the byte at index removed; panics if out of bounds
set_char_at
(s string, index i64, c char) -> string
New string with the byte at index replaced by c; panics if out of bounds
Remove prefix if present, otherwise return unchanged
remove_suffix
(s string, suffix string) -> string
Remove suffix if present, otherwise return unchanged
replace
(s string, old string, new string) -> string
Replace all occurrences
repeat
(s string, count i64) -> string
Repeat string
reverse
(s string) -> string
Reverse string
truncate
(s string, max i64, ellipsis string) -> string
Return s unchanged if len(s) <= max, else the first max - len(ellipsis) bytes plus ellipsis (total byte length exactly max); panics if max < len(ellipsis)
string is an immutable value type, so building one with repeated += reallocates
and copies the whole accumulated content each time — assembling N pieces is O(N²).
Builder is a growable byte accumulator that appends in place and is finalized to a
string once, making the same work amortized O(M) in the total byte count M.
Builder is arena-managed like any struct: it goes out of scope with its enclosing
arena, with no manual free. The buffer grows by doubling. strings.builder_clear
keeps the allocated capacity, so a builder can be reused across frames of a loop
without reallocating.
Every operation on a Builder mutates it, so it must be declared mut — a const
builder is a compile error (E3062). The builder_append* calls take the builder by
reference with no & at the call site, but — like an array — a function that appends
to a builder passed in by the caller must take it as &b Builder; appending through a
plain (immutable) parameter is a compile error (E5007).
Function
Signature
Description
builder
() -> Builder
Create an empty builder
builder_reserve
(b Builder, n i64) -> void
Grow the buffer to hold at least n bytes; a negative n is ignored
builder_append
(b Builder, s string) -> void
Append the bytes of s
builder_append_char
(b Builder, c char) -> void
Append the codepoint c, UTF-8 encoded (1–4 bytes)
builder_append_bytes
(b Builder, data [u8]) -> void
Append every byte of data
builder_append_i64
(b Builder, n i64) -> void
Append the decimal text of n
builder_append_line
(b Builder, s string) -> void
Append s followed by a newline
builder_len
(b Builder) -> i64
Bytes accumulated so far
builder_clear
(b Builder) -> void
Reset length to zero, keeping capacity
build
(b Builder) -> string
Copy the accumulated bytes into a new string; the builder stays usable