String

String

The string type and its methods.

string

class string

The UTF-8 string type. Immutable-by-default text with cheap literals and an owned, growable heap form.

data is bytes and len counts them; codepoints() counts the Unicode codepoints they encode. A string literal is borrowed (points into static storage, capacity() == 0, no allocation); the first mutation moves it to the heap. Every string keeps a NUL after len, so c_str() is O(1). Copying an owned string is a deep copy; copying a borrowed one shares the static bytes. Indexing is by byte and is not bounds-checked.

Example

var s = "héllo"
s += " wörld"
var bytes = s.length()
var chars = s.codepoints()

Generated from Kairo source, Apache-2.0 WITH AdditionRef-Kairo-Runtime-exception.