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

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'
主站蜘蛛池模板: 方山县| 泸溪县| 阿图什市| 温泉县| 鄄城县| 左权县| 台湾省| 利辛县| 贵州省| 宜昌市| 搜索| 余姚市| 汉阴县| 称多县| 镇赉县| 台江县| 江源县| 桐柏县| 兴义市| 河源市| 秀山| 邵武市| 南陵县| 乐陵市| 莱州市| 锦州市| 会昌县| 辽宁省| 乐都县| 疏勒县| 襄樊市| 荆州市| 双鸭山市| 朔州市| 攀枝花市| 扶余县| 天柱县| 潞城市| 六枝特区| 社旗县| 岑溪市|