Character literals

Character literals are enclosed in single quotes ‘’ and can contain the same escape sequences as strings - with one exception: the platform dependent newline (\p) is not allowed as it may be wider than one character (often it is the pair CR/LF for example). Here are the valid escape sequences for character literals:

Escape sequenceMeaning
\r, \ccarriage return
\n, \lline feed
\fform feed
\ttabulator
\vvertical tabulator
\backslash
\”quotation mark
\’apostrophe
\ ‘0’..’9’+character with decimal value d; all decimal digits directly following are used for the character
\aalert
\bbackspace
\eescape [ESC]
\x HHcharacter with hex value HH; exactly two hex digits are allowed

A character is not an Unicode character but a single byte. The reason for this is efficiency: for the overwhelming majority of use-cases, the resulting programs will still handle UTF-8 properly as UTF-8 was specially designed for this. Another reason is that Nim can thus support array[char, int] or set[char] efficiently as many algorithms rely on this feature. The Rune type is used for Unicode characters, it can represent any Unicode character. Rune is declared in the unicode module.