Characters
Characters are represented by the type Char
. Character literals go in single quotes: '1'
.
Special characters start from an escaping backslash \
. The following escape sequences are supported:
\t
– tab\b
– backspace\n
– new line (LF)\r
– carriage return (CR)\'
– single quotation mark\"
– double quotation mark\\
– backslash\$
– dollar sign
To encode any other character, use the Unicode escape sequence syntax: '\uFF00'
.
fun main() { //sampleStart val aChar: Char = 'a' println(aChar) println('\n') // Prints an extra newline character println('\uFF00') //sampleEnd }
If a value of character variable is a digit, you can explicitly convert it to an Int
number using the digitToInt()
function.
10 February 2025