Standard library / String methods · on the one-page reference

String methods

Stable — pure slice operations, no I/O, conformance-covered.

Called directly on any string value.

APIType
s.length · s + t · s.concat(t, …)int · concatenation · string (variadic)
s.split(sep, limit?)(string | regex, int) → string[] (splits on a string or a regex separator; at most limit parts for the string form)
s.slice(start, end?) · s.substring(start, end)→ string
s.indexOf(sub, from?) · s.lastIndexOf(sub) · s.includes(sub, from?)→ int · int · bool
s.search(regex)regex → int (index of the first match, or −1)
s.startsWith(prefix, pos?) · s.endsWith(suffix, end?)→ bool
s.localeCompare(t)string → int (−1 / 0 / 1 by byte order; use as a sort comparator)
s.toUpperCase() · s.toLowerCase() · s.trim()→ string
s.trimStart() · s.trimEnd()→ string
s.repeat(n) · s.padStart(len, pad?) · s.padEnd(len, pad?)→ string (pad defaults to a space)
s.replace(from, to) · s.replaceAll(from, to)→ string (from is a string or a regex; a regex with the g flag replaces every match, otherwise the first)
s.charAt(i) · s.at(i) · s.charCodeAt(i) · s.codePointAt(i)→ string · string · int · int (at allows negative index; byte-oriented)
String.isEmpty(s) · String.contains(s, sub)→ bool
String.compare(a, b)(string, string) → int (−1 / 0 / 1; use as an array sort comparator)
String(x)number | bool | string → string (global conversion)
Boolean(x)number | bool | string → bool (truthiness: nonzero / nonempty / itself)
Number(x)number | bool | string → f64 (NaN if a string doesn't parse)
String.fromCharCode(code, …) · String.fromCodePoint(code, …)(int, …) → string (one byte per code, each & 0xFF)