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

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'
主站蜘蛛池模板: 泽库县| 澎湖县| 霍州市| 浑源县| 麻城市| 通榆县| 馆陶县| 徐水县| 遂昌县| 宁津县| 云霄县| 通辽市| 大荔县| 开平市| 阿拉善盟| 庄河市| 西安市| 泰顺县| 曲沃县| 龙南县| 泸西县| 明星| 湘潭县| 和顺县| 屯昌县| 庆城县| 海盐县| 怀仁县| 台州市| 浪卡子县| 苏尼特左旗| 甘谷县| 巢湖市| 乡宁县| 大宁县| 汽车| 永昌县| 金塔县| 泽普县| 迁西县| 高淳县|