API Reference › Text › Text.char_at
method

Text.char_at

Text.char_at(s, i) -> int

Returns the byte at position i in s as an int in the range 0..255 — for example Text.char_at("hello", 0) is 104, the code for h. Indices are zero-based and count bytes. Use it to inspect or classify individual characters, such as testing whether a key of input is a digit.

Parameters

sthe string to read from
ithe zero-based byte index

Example

program FirstIsDigit {
  var entry: string = "7up"

  handler Check phase Update {
    let c = Text.char_at(entry, 0)
    let is_digit = c >= 48 and c <= 57   # true: '7'
  }
}
← All symbols