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

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.

主站蜘蛛池模板: 华阴市| 昭觉县| 土默特右旗| 兴仁县| 通道| 长海县| 烟台市| 道孚县| 芜湖县| 包头市| 河曲县| 曲阳县| 砀山县| 潢川县| 元氏县| 商城县| 林西县| 合水县| 麻城市| 安吉县| 会昌县| 天长市| 长春市| 水富县| 台湾省| 阿图什市| 瓮安县| 靖远县| 闸北区| 开封县| 珠海市| 台湾省| 依兰县| 含山县| 望谟县| 天等县| 晋中市| 尤溪县| 武陟县| 衡阳市| 霍林郭勒市|