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

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.

主站蜘蛛池模板: 兴安盟| 讷河市| 郴州市| 吉林市| 黑河市| 海林市| 文山县| 绥德县| 德保县| 庆安县| 石泉县| 龙州县| 鸡西市| 博乐市| 井研县| 漯河市| 永宁县| 济阳县| 石柱| 伊通| 封丘县| 五莲县| 宁陕县| 长春市| 宝兴县| 湟中县| 徐州市| 信宜市| 隆昌县| 成都市| 乌海市| 白山市| 锡林郭勒盟| 本溪| 灯塔市| 海盐县| 图木舒克市| 普兰店市| 甘德县| 南召县| 将乐县|