Skip to content

Strings

Strings in Run are UTF-8 encoded byte sequences. The string type is string.

package main
use "fmt"
pub fun main() {
greeting := "Hello, Run!"
fmt.println(greeting)
}

Iterating over a string yields characters (Unicode code points) by default.

Ranging over a string directly gives you one character per iteration. This handles multi-byte UTF-8 sequences correctly.

for ch in greeting {
fmt.println(ch)
}

Use .bytes to iterate over the raw bytes of a string instead.

for b in greeting.bytes {
fmt.println(b)
}

Byte iteration is faster but does not respect character boundaries — a multi-byte character will appear as multiple separate bytes.