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

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.

主站蜘蛛池模板: 泸西县| 黑水县| 桐乡市| 温宿县| 红桥区| 留坝县| 贵溪市| 连云港市| 常熟市| 镇沅| 开远市| 福建省| 剑河县| 赣州市| 雅江县| 常宁市| 沙田区| 岳池县| 哈巴河县| 伊吾县| 梨树县| 浏阳市| 临潭县| 香河县| 内丘县| 铁岭市| 平湖市| 临清市| 灵宝市| 全南县| 桐梓县| 洛南县| 刚察县| 榕江县| 简阳市| 绍兴县| 湾仔区| 眉山市| 武宁县| 柞水县| 枣阳市|