Skip to main content

Standard Library: Text & Strings

Text helpers are UTF-8 aware: len(string) and indices count Unicode code points, not bytes.


Functions​

FunctionSignatureDescription
lenlen(s: str): intCode-point count
textUppertextUpper(s: str): strUppercase
textLowertextLower(s: str): strLowercase
textTrimtextTrim(s: str): strStrip leading/trailing whitespace
textContainstextContains(s: str, sub: str): boolSubstring test
textFindtextFind(s: str, sub: str): int?First index, or null
textSlicetextSlice(s: str, start: int, end?: int): strSlice by code points
textSplittextSplit(s: str, delim: str): arraySplit on delimiter
textReplacetextReplace(s: str, from: str, to: str): strReplace 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"));