Strings
Literal syntax
Strings are UTF-8 byte sequences delimited by double quotes:
let s = "hello, karkain"
Indexing
Individual bytes are accessed by integer index (0-based):
let s = "abc"
print(s[0]) // 97 (ASCII 'a')
Concatenation
Strings are joined with the + operator:
let first = "hello"
let second = " world"
print(first + second) // hello world
Built-in functions
len(s)Returns the byte length of the string.
substr(s, start, end)Returns a substring from byte index start to end (exclusive).
trim(s)Strips leading and trailing whitespace.
split(s, sep)Splits the string into an array on the separator.
contains(s, sub)Returns
trueif sub is found in s.str(value)Converts an
intorfloat64to its string representation.int(s)Parses a string as an
int(runtime error on invalid input).
Standard library: std.string
Additional string utilities are available through the standard library:
import std.string
let upper = std.string.to_upper("hello")
let lower = std.string.to_lower("HELLO")
print(upper)
print(lower)