Strings
String type
let greeting: string = "Hello, world!";In t1/t2, string is an owned, heap-allocated UTF-8 sequence.
String interpolation
let name = "tape";
let version = 2;
let msg = "Welcome to {name} v{version}!";Expressions inside {} are evaluated and converted to their string representation.
Escape sequences
| Escape | Meaning |
|---|---|
\n | Newline |
\t | Tab |
\r | Carriage return |
\\ | Backslash |
\" | Double quote |
\0 | Null byte |
\xHH | Hex byte |
\{ | Literal { (suppresses interpolation) |
\} | Literal } |
Use \{ and \} when you need literal braces alongside interpolation:
let json = "\{\"name\": \"{name}\", \"age\": {age}\}";
// Output: {"name": "tape", "age": 25}Triple-quoted strings
Triple-quoted strings can span multiple lines and contain " without escaping:
let html = """
<div class="container">
<p>Hello, {name}!</p>
</div>
""";Escape sequences and interpolation are active inside triple-quoted strings.
Raw strings
Prefix triple quotes with r to disable all escape sequences and interpolation:
let json = r"""{"name": "tape", "version": 2}""";Raw strings can span multiple lines and contain quotes freely:
let shader = r"""
#version 330 core
void main() {
gl_Position = vec4(0.0);
}
""";
let config = r"""
{
"host": "localhost",
"port": 8080
}
""";Rules:
- No escape sequences — backslash is a literal character
- No interpolation — braces are literal characters
- Multi-line — newlines are preserved as-is
- Can contain
"freely — ends only at""" - Cannot contain the literal sequence
""" - Same type as regular strings (
stringin t1/t2,[]const u8in t0)
Strings in t0
The string type is not available in t0 (no heap). Use byte slices instead:
let msg: []const u8 = "Hello from kernel";String operations
The str standard library operates on *u8 + length pairs:
import str from "str";
var buf: *u8 = "hello";
str.to_upper(buf, 5); // in-place case conversion
let n: u32 = str.len(buf); // null-terminated length
let eq: bool = str.equal(a, a_len, b, b_len);
let idx: i32 = str.index_of(haystack, h_len, needle, n_len);Available functions: len, char_at, equal, starts_with, ends_with, index_of, contains, copy, concat, to_upper, to_lower, trim_left, trim_right, parse_i64, i64_to_str, i64_to_cstr.
Last modified: