Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I escape special symbols in scala string?

Is there a general Scala utility method that converts a string to a string literal? The simple lambda function "\"" + _ + "\"" only works for strings without any special characters.

For example, the string \" (length 2) should be converted to the string "\\\"" (length 6).

like image 363
fredoverflow Avatar asked Jun 27 '13 10:06

fredoverflow


1 Answers

Wrap the String with 3 quotes to represent it as is..

e.g. val str = """ \" """ // str : java.lang.String = \"

like image 50
Shrey Avatar answered Sep 26 '22 02:09

Shrey