String Methods
This content is for v0.7. Switch to the latest version for up-to-date documentation.
Method Reference
Section titled “Method Reference”| Method | Description |
|---|---|
length() | Get character count (Unicode-aware) |
uppercase() | Convert to uppercase |
lowercase() | Convert to lowercase |
substring(start, end) | Extract substring [start, end) |
split(delimiter) | Split into array by delimiter |
contains(str) | Check if contains substring |
trim() | Remove leading/trailing whitespace |
replace(old, new) | Replace all occurrences |
starts_with(prefix) | Check if starts with prefix |
ends_with(suffix) | Check if ends with suffix |
iter() | Create iterator over characters |
Examples
Section titled “Examples”let s = "Hello World";
// Case conversions.uppercase(); // "HELLO WORLD"s.lowercase(); // "hello world"
// Inspections.length(); // 11s.contains("World"); // trues.starts_with("Hello"); // trues.ends_with("World"); // true
// Transformations.substring(0, 5); // "Hello"s.split(" "); // #["Hello", "World"]s.replace("World", "Resonon"); // "Hello Resonon"
// Whitespace handlinglet padded = " text ";padded.trim(); // "text"
// Iterator"hello".iter().take(3).collect(); // ["h", "e", "l"]"hello".iter().filter(fn(c) { return c != "l"; }).collect(); // ["h", "e", "o"]See Also
Section titled “See Also”- Strings - String basics
- Iterator Methods - Full iterator API available via
.iter()