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.
Last modified: 10 August 2022
© 2010–2023 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/docs/characters.html