Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Strings

The Quick Tour already introduced String: immutable Utf-8 text, ASCII-7 as a proper subset, and the caution that str::len is a byte length, not a character count. Literals (quoted, raw, and rune ticks) are covered under Interpreter. Comparison of two Strings uses Utf-8 byte ordering (Basic Operators).

This section is the day-to-day API for working with text:

PageContents
Unicode and Utf-8How Utf-8 is coded, why finds stay unambiguous, and why that does not slow ordinary string work
String OperatorsThe full str:: family: length, trim, case, concat, probes, split/join
Iterating Runesforeach over a String (code points as Int) plus a worked census example
StringBuilderMutable accumulation when many concatenations would be costly

A few design points that shape every API below:

  • Immutability — every str:: “mutation” returns a new String; the inputs are unchanged.
  • Stack operators, not instance methods — text helpers are the str::… words (same family style as other axiom groups). Park a String on ts only when you need several rooted object ops around it; for pure string transforms, keep values on DS.
  • No byte-indexed substring — cutting at an arbitrary byte offset can split a multi-byte character. Build pieces with StringBuilder, use str::indexOf /str::sub / str::split, or iterate runes (this section and TextReader).
  • Truthy — "" is false; any non-empty String is true (Basic Types).

For line-oriented or file-backed text, prefer Text and Byte Streams. For pattern matching, see Regex (later in the survey).