Skip to content
kata / a language workbench

Strings and bytes

Str holds text. Double quotes enable expression interpolation; single quotes keep braces literal. Both forms process escape sequences.

let name = "Ada"
print("hello, {name}") # hello, Ada
print('hello, {name}') # hello, {name}
print("six times seven: {6 * 7}")

Common escapes include \n, \t, \r, \\, \', and \". In an interpolated string, \{ and \} produce literal braces. Unicode escapes use four digits with \uNNNN or eight with \UNNNNNNNN.

let text = " Small Steps "
let clean = text.trim().to_lower()
print(clean) # small steps
print(clean.contains("steps")) # true
print(clean.replace("small", "steady"))

Other methods include starts_with, ends_with, trim_start, trim_end, and to_upper.

split(delimiter) returns an Arr[Str]:

let names = "Ada,Lin,Sam".split(",")
for name in names {
print(name)
}

An empty delimiter splits into individual codepoint strings with empty parts at both boundaries. The word-frequency tutorial combines normalization, splitting, and counting.

let word = "héllo"
print(word.len()) # 5
print(word.substr(1, 1)) # é
print(word.to_bin().len()) # 6 UTF-8 bytes

substr(start, length) uses codepoint positions. A displayed character can contain multiple codepoints, so these operations are not grapheme-cluster indexing.

chars() returns Arr[Char]. Single quotes still produce a Str; they are not a character-literal syntax.

let packet = b'hi\xff'
print(typeof(packet)) # Bin
print(packet.len()) # 3

b"..." supports interpolation; b'...' does not. In byte strings, \xNN contributes one raw byte. Str.to_bin() encodes text as UTF-8. This distinction keeps binary data separate from text.

"42".to_int() and "3.5".to_float() convert valid text. Invalid input currently produces a runtime error; these methods do not return Res. Adding ? does not catch that failure. Use explicit validation and a result-returning API when designing your own operations.