且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在scala字符串中避免特殊符号?

更新时间:2023-02-19 12:31:54

看看Apache Common的 StringEscapeUtils class( docs here 一>)。 escapeJava 应该完成工作。



看看这个例子看到它在行动(在Java中)。 p>

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).

Have a look at Apache Common's StringEscapeUtils class (docs here). escapeJava should get the job done.

Have a look at this example to see it in action (in Java).