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

The raw interpolator

The final one pre-existing interpolator in Scala is the raw interpolator. This interpolator does not allow you to use any escape sequence characters in your string, it means that if you try to give an escape sequence character, it'll be treated as a normal literal and nothing more. The way we write raw interpolator is almost similar to the other two interpolators. We precede our String with a raw keyword and it works for us:

scala> val rawString = raw"I have no escape \n character in the String \n "
rawString: String = "I have no escape \n character in the String \n "

Here, in the string escape character, \n was treated as a normal literal, and in the resulting string it remained the same. In a normal string, \n would have converted into a newline character.

scala> val rawString = "I have no escape \n character in the String \n "
rawString: String =
"I have no escape
character in the String
"

Using this raw interpolator, we can avoid escape sequences. These constructs give us a way to write code more efficiently and concisely.

主站蜘蛛池模板: 白朗县| 黄山市| 龙里县| 龙门县| 旬阳县| 海口市| 崇仁县| 台中市| 新野县| 东海县| 宁陕县| 大庆市| 晴隆县| 奈曼旗| 昂仁县| 三江| 宣恩县| 镇宁| 铅山县| 西畴县| 天峻县| 石台县| 息烽县| 精河县| 土默特右旗| 洪洞县| 抚松县| 遵义县| 岳池县| 昭平县| 育儿| 太原市| 怀柔区| 乌拉特前旗| 平顺县| 彩票| 肃宁县| 洛川县| 信阳市| 棋牌| 丰都县|