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"
+ on two strings is concatenation. Both operands are strings: "a" + 1 is
a type error. fmt writes values of any type into a template, one {} each,
and join puts a list of strings together with a separator:
["Dune" + " (1965)", fmt("{} has {} pages", "Dune", 412), ["a", "b", "c"].join(", ")]
["Dune (1965)", "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.