Standard Library: Text & Strings
Text helpers are UTF-8 aware: len(string) and indices count Unicode code points, not bytes.
Functions
| Function | Signature | Description |
|---|---|---|
len | len(s: str): int | Code-point count |
textUpper | textUpper(s: str): str | Uppercase |
textLower | textLower(s: str): str | Lowercase |
textTrim | textTrim(s: str): str | Strip leading/trailing whitespace |
textContains | textContains(s: str, sub: str): bool | Substring test |
textFind | textFind(s: str, sub: str): int? | First index, or null |
textSlice | textSlice(s: str, start: int, end?: int): str | Slice by code points |
textSplit | textSplit(s: str, delim: str): array | Split on delimiter |
textReplace | textReplace(s: str, from: str, to: str): str | Replace occurrences |
There is no import std.text. Call these as globals.
Examples
const pieces = textSplit("one::two::three", "::");
const line = textTrim(" alice , admin ");
const columns = textSplit(line, ",");
print(textContains("hello", "ell"), pieces[0], textLower("API"));