如何在Java中转义字符串? [英] How do I escape a string in Java?
问题描述
\\\
和 \t
您应该使用着名的Apache Commons中的StringEscapeUtils库。您会发现Apache Commons中有很多其他产品可能对您在Java开发中的其他问题有用,因此您不要重新发明。
您想要的具体调用与Java转义有关; API调用是StringEscapeUtils.escapeJava()。在该图书馆里还有很多其他的转义工具。
I'm reading a sourcefile in Java, but when I print it (sysout), the escaped characters are no longer escaped. How can I escape characters like \n
and \t
in a string in Java?
You should use the StringEscapeUtils library from the well-known Apache Commons. You'll find that there are plenty of other offerings in Apache Commons that might serve useful for other problems you have in Java development, so that you don't reinvent the wheel.
The specific call you want has to do with "Java escaping"; the API call is StringEscapeUtils.escapeJava(). There are plenty of other escaping utilities in that library as well.
这篇关于如何在Java中转义字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!