String
Capy
type string
string stores text, raw bytes, and HTML literal results in Capy.
A string literal and an HTML literal both yield a string. Use variables, parameters, and return values directly. Functions can build and return HTML strings like other strings.
<?= value ?> escapes a string for HTML text, a quoted attribute, a script, or a style. <?: value ?> emits a string without escaping. Use raw interpolation only for source-controlled HTML text.
An HTML literal inside <?= ?> becomes escaped text. This double escape is expected. An any uses its string conversion before escaping.
Use length, find, contains, replace, lower, upper, and substr for common text work. Use split_utf8 when you must split UTF-8 text by characters.
Strings do not require valid UTF-8. length and substr count bytes, so length("é") is 2. A byte slice can cut a UTF-8 character in half. Use length(split_utf8(text)) to count the items produced by UTF-8 splitting. Use string(text, validate_utf8: true) when invalid UTF-8 must stop the request. This check does not repair bytes.
Strings are not Boolean conditions. Use text != "" for nonempty text. bool(any(text)) parses Boolean text and is not an emptiness test.
var name := "Ada"
var page := <><p><?= upper(name) ?></p></>
print(page, "\n")
Output
<p>ADA</p>