stringString manipulation utilities.
Functions for searching, slicing, transforming, and converting strings. These supplement the built-in string operations.
import std::string;
fn main() {
let s = " Hello, World! ";
let trimmed = string.trim(s);
let lower = string.to_lower(trimmed);
println(lower); // "hello, world!"
}
findFind the first occurrence of needle in haystack.
Returns the byte offset, or -1 if not found.
let pos = string.find("hello world", "world"); // 6
sliceExtract a substring by byte indices [start, end).
let s = string.slice("hello", 1, 4); // "ell"
trimStrip leading and trailing whitespace.
let s = string.trim(" hello "); // "hello"
replaceReplace all occurrences of from with to in the input string.
let r = string.replace("aabbcc", "bb", "xx"); // "aaxxcc"
splitSplit a string by a delimiter.
Returns the substrings joined by newlines (the runtime does not yet support returning arrays from FFI).
to_lowerConvert a string to lowercase.
let s = string.to_lower("HELLO"); // "hello"
to_upperConvert a string to uppercase.
char_atReturns the character code at the given byte index.
repeatRepeat a string n times.
let s = string.repeat("ab", 3); // "ababab"
index_ofFind the first occurrence of needle starting from start_index.
Returns the byte offset, or -1 if not found.
starts_withTest whether s starts with the given prefix.
ends_withTest whether s ends with the given suffix.
containsTest whether haystack contains needle.
from_intConvert an integer to its string representation.
let s = string.from_int(42); // "42"
from_floatConvert a float to its string representation.
from_boolConvert a bool to "true" or "false".
from_charConvert a character code to a single-character string.
let newline = string.from_char(10);
to_intParse a string as an integer. Returns 0 if parsing fails.
let n = string.to_int("42"); // 42