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

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'
主站蜘蛛池模板: 文登市| 东至县| 桐城市| 龙陵县| 柳江县| 汉寿县| 天峨县| 内江市| 修武县| 手游| 施甸县| 临安市| 台东市| 陕西省| 钟祥市| 瓦房店市| 抚州市| 阳信县| 赤峰市| 贡嘎县| 桓台县| 湘西| 宜丰县| 新竹市| 丹阳市| 台安县| 罗定市| 和平区| 炎陵县| 武定县| 平山县| 舒城县| 通江县| 安岳县| 兰州市| 宜兴市| 平武县| 清水县| 徐汇区| 广饶县| 安康市|