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

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.

主站蜘蛛池模板: 泰州市| 攀枝花市| 顺平县| 台北县| 蓝田县| 达州市| 宣城市| 沙河市| 锡林浩特市| 沧源| 永善县| 宜君县| 竹山县| 沿河| 沧源| 临海市| 南江县| 廊坊市| 敦煌市| 和平县| 当阳市| 蒙城县| 绥中县| 定兴县| 镇安县| 罗城| 泊头市| 滦南县| 车致| 手游| 府谷县| 松滋市| 托里县| 察隅县| 渑池县| 牡丹江市| 将乐县| 门头沟区| 海南省| 门头沟区| 宝兴县|