String (Type)

String literals use UTF-8. Interpolate values with ${...} and use escapes such as \n for a newline.

Example

let name = "Zoë"
print("Hello, ${name}! ${byteLength(name)} bytes")
name = "Zoë"
print "Hello, ${name}! ${byteLength name} bytes"

Both programs print Hello, Zoë! 4 bytes: ë occupies two bytes. byteLength counts bytes, and substring and indexOf use byte offsets. Choose code-point boundaries when slicing; codePointAt decodes a Unicode code point at a byte offset and returns Error for malformed UTF-8.