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

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.

主站蜘蛛池模板: 高邮市| 获嘉县| 沧州市| 磴口县| 洛阳市| 策勒县| 汉川市| 咸阳市| 德安县| 东宁县| 宜黄县| 疏附县| 舟山市| 胶州市| 吉隆县| 仲巴县| 合作市| 元朗区| 股票| 绍兴县| 南康市| 金平| 清河县| 华亭县| 沙雅县| 德庆县| 永州市| 陆丰市| 城固县| 东山县| 博客| 阳春市| 靖宇县| 米泉市| 林甸县| 玛纳斯县| 平乐县| 红桥区| 嘉峪关市| 广州市| 葫芦岛市|