Strings
String Operations (std.string)
import std.string
let parts: List[string] = std.string.split("hello world", " ")
let trimmed: string = std.string.trim(" hello ")
let has: bool = std.string.contains("hello world", "world")
let upper: string = std.string.to_upper("hello")
let replaced: string = std.string.replace("hello world", "world", "kira")
let chars: List[char] = std.string.chars("hello")
let len: i32 = std.string.length("hello") // 5String Interpolation
Strings support embedded expressions with ${expr}:
let name: string = "Alice"
let age: i32 = 30
let msg: string = "Hello, ${name}! You are ${age} years old."String Concatenation
Use + to concatenate strings:
let full: string = "Hello, " + name + "!"String Builder (std.builder)
For efficient string concatenation when building large strings:
effect fn build_greeting(names: List[string]) -> string {
var b: StringBuilder = std.builder.new()
b = std.builder.append(b, "Hello to: ")
for name in names {
b = std.builder.append(b, name)
b = std.builder.append(b, ", ")
}
return std.builder.build(b)
}Character Operations (std.char)
fn is_vowel(c: char) -> bool {
let code: i32 = std.char.to_i32(c)
return code == 97 or code == 101 or code == 105 or code == 111 or code == 117
}
fn process_chars(s: string) -> List[char] {
return std.string.chars(s)
}