Quirrel4.41.0

types.Integer.tochar

Method on every integer
pure (bool|number).tochar(): any

Converts the integer to a one-character string, treating it as a character code.

Return value

A string of length 1 whose only byte is this cast to char.

Notes

Takes no arguments. The cast wraps modulo 256 and keeps no sign information, the same as a C (char) cast: (65).tochar() and (65 + 256).tochar() give the same character. A negative or out-of-[0, 255] value does not throw, it wraps.

This method also exists on float and bool (see types.Float.tochar and types.Bool.tochar); bool's version produces a control character rather than a printable one, since true casts to 1.

Example

examples/types/integer/tochar.nut
println("(65).tochar() =", (65).tochar())
println("(65).tochar() == (65 + 256).tochar() =", (65).tochar() == (65 + 256).tochar()) // the (char) cast wraps mod 256
println("(65).tochar().len() =", (65).tochar().len())
Output:
(65).tochar() = A
(65).tochar() == (65 + 256).tochar() = true
(65).tochar().len() = 1

See also

tostringConverts the integer to its decimal string form.
tocharConverts the float to a one-character string, treating it as a character code.
tocharConverts the bool to a one-character string, treating it as a character code.
integerclass index