A Char represents a Unicode code point. It occupies 32 bits.
It is created by enclosing an UTF-8 character in single quotes.
'a' 'z' '0' '_' 'あ'
You can use a backslash to denote some special characters:
'\'' # single quote '\\' # backslash '\e' # escape '\f' # form feed '\n' # newline '\r' # carriage return '\t' # tab '\v' # vertical tab
You can use a backslash followed by at most three digits to denote a code point written in octal:
'\101' # == 'A' '\123' # == 'S' '\12' # == '\n' '\1' # code point 1
You can use a backslash followed by an u and four hexadecimal characters to denote a unicode codepoint written:
'\u0041' # == 'A'
Or you can use curly braces and specify up to six hexadecimal numbers (0 to 10FFFF):
'\u{41}' # == 'A' '\u{1F52E}' # == '🔮'
To the extent possible under law, the persons who contributed to this workhave waived
all copyright and related or neighboring rights to this workby associating CC0 with it.
https://crystal-lang.org/docs/syntax_and_semantics/literals/char.html