Skip to content

Strings

Strings are text values.

Use single or double quotes for strings:

const name: string = "John"
println(name)

Use + to concatenate strings:

const data = "Nubo"
println(data + "!")

Use backticks for template strings with ${...} interpolation:

struct User {
name: string
}
impl User {
fn sayHello(self: User) void {
println(`Hi! I am ${self.name}!`)
}
}

Strings support length():

type hasLen: iface {
length() int
}
fn len(obj: hasLen) int {
return obj.length()
}
const name: string = "John"
println(len(name))

Use bytes() to work with the bytes of a string:

let x: int = 0
bytes("hello").map(int).each(fn(n: int) {
x = x + n
})
println(x)