- Android Development with Kotlin
- Marcin Moskala Igor Wojda
- 127字
- 2021-07-02 18:48:36
Char
Characters in Kotlin are stored in type Char. In many ways, characters are similar to strings, so we will concentrate on the similarities and differences. To define Char, we must use single quote, as opposed to a String where we are using double quotes:
val char = 'a' // 1 val string = "a" // 2
- Defines a variable of type Char.
- Defines a variable of type String.
In both characters and strings, special characters can be escaped using a backslash. The following escape sequences are supported:
- \t: Tabulator
- \b: Backspace
- \n: New line
- \r: Carriage-return
- \': Quote
- \": Double quote
- \\: Slash
- \$: Dollar character
- \u: Unicode escape sequence
Let's define a Char containing the Yin Yang Unicode character (U+262F):
var yinYang = '\u262F'