String¶
A String is text, written in double quotes. Its functions are called on it
with a dot:
"Ada Lovelace".upper()
"ADA LOVELACE"
Its length counts characters, not bytes:
"héllo".length()
5
A position reads one character. It may be past the end, so it gives an
Option<String>, printed as the character when it is present:
"Dune"[0]
"D"
Strings are not added with +. fmt writes values into a template, one {}
each, and join puts a list of strings together:
[fmt("{} has {} pages", "Dune", 412), ["a", "b", "c"].join(", ")]
["Dune has 412 pages", "a, b, c"]
split, trim, replace_all, starts_with, contains and the rest are in
the string module, visible in every program:
" Frankenstein ".trim().starts_with("Frank")
true
A String is Orderable, in the order of its characters, so a list of them
sorts. Any value becomes text with str.