SplitScript reference / String / charAt

String.charAt

Method

String.charAt(byteIndex: u32) -> char!

Returns the Unicode character beginning at a UTF-8 byte offset.

The index uses the same zero-based byte offsets as byteLength and slice, not JavaScript's UTF-16 code-unit indexes. The index must point to the first byte of a character. An out-of-range index or a continuation-byte index returns an error.

Parameters

  • byteIndex: The zero-based UTF-8 byte offset of the character's first byte.

Effects: allocates

Runtime behavior: available everywhere; synchronous

Examples

Inspect a non-ASCII character

let sharpS = "Straße".charAt(4) else '\0'
if sharpS == 'ß' {
    print("Found sharp S")
}