Quirrel4.41.0

types.Bool.tochar

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

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

Return value

A string of length 1: chr(1) for true, chr(0) (a NUL byte) for false. Neither is printable - true's casts to the same character code as (1).tochar(), a control character, not a letter or digit.

Notes

Takes no arguments. See types.Integer.tochar for the general (char)-cast mechanism this shares.

Example

examples/types/bool/tochar.nut
// true.tochar() is chr(1), a control character - print its code, not the raw byte.
let c = true.tochar()
println("c.len() =", c.len())
println("c[0] =", c[0])
println("false.tochar()[0] =", false.tochar()[0])
Output:
c.len() = 1
c[0] = 1
false.tochar()[0] = 0

See also

tocharConverts the integer to a one-character string, treating it as a character code.
tocharConverts the float to a one-character string, treating it as a character code.
tointegerConverts the bool to an integer.
boolclass index