如何在scala字符串中避免特殊符号? [英] How can I escape special symbols in scala string?
本文介绍了如何在scala字符串中避免特殊符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一个通用的Scala实用程序方法将字符串转换为字符串文字?简单的lambda函数\+ _ +\
仅适用于没有任何特殊字符的字符串。
例如,字符串 \
(长度2)应转换为字符串\\\
(length 6)。
解决方案
看看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).
这篇关于如何在scala字符串中避免特殊符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文