官术网_书友最值得收藏!

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 
  1. Defines a variable of type Char.
  2. 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'
主站蜘蛛池模板: 万全县| 库伦旗| 龙陵县| 包头市| 奇台县| 津市市| 安泽县| 恩平市| 乌什县| 绥化市| 新郑市| 柳江县| 元江| 沾化县| 芦溪县| 宜君县| 常山县| 肥城市| 张家界市| 广灵县| 车致| 专栏| 中宁县| 吉木萨尔县| 嵊泗县| 汶上县| 潍坊市| 凭祥市| 赫章县| 富裕县| 城固县| 大姚县| 永兴县| 休宁县| 吉隆县| 定安县| 东至县| 乃东县| 兴宁市| 海南省| 将乐县|