LEARN VOID / DATA & BEHAVIOR
Strings & Unicode
Use one text type throughout ordinary code.
Illustrative fragment — place this code inside a function. It is verified in an executable context, but the download is not a standalone program.
const name = "世界"
var message = "Hello, {name}!"Create and combine text
The local fragment inserts a string name into a greeting. The value is "Hello, 世界!". Interpolation needs no prefix: "{name}" evaluates its string expression once. Use {{ and }} for literal braces. Numeric, Boolean and custom-value interpolation, format specifications and multiline string literals remain future work. This fragment does not print anything.
Rebind without changing earlier text
String content is immutable; assignment can share that content safely. Concatenation with + creates combined text; += rebinds a mutable string without changing earlier text. A defaultable uninitialized string local or field starts empty.
Understand Unicode and API limits
Strings compare exact UTF-8 content without Unicode normalization. Supported escapes include \n, \t and scalar escapes such as \u{e9}. text.length counts Unicode scalars; text.byte_length counts UTF-8 bytes, both as i64. text[index] returns a one-scalar string and accepts negative indexes. It raises a checked failure out of bounds. Scalars are not grapheme clusters: combining marks can count separately. Printing and automatic numeric conversion are not supplied by these operations.
Convert UTF-8 explicitly
"café" has four scalars and five UTF-8 bytes. to_utf8() creates an independent owned byte list. string.from_utf8(bytes) copies and validates bytes, returning result<string, string>; invalid input returns Err("invalid UTF-8"). This program returns the decoded scalar count. The adapter input is unused.
func entry(input: i32) -> i32:
var bytes = "café".to_utf8()
var decoded = string.from_utf8(bytes)
return match decoded:
Ok(var text): text.length as i32
Err(var reason): 0