标签: java string string-literals
可能重复: How would you convert a String to a Java string literal?
是否有一个库函数接受一个字符串并将其转换为相应的字符串文字?例如:
Please say\ask "What?" three times! - > "Please say\\ask \"What?\" three times!"
Please say\ask "What?" three times!
"Please say\\ask \"What?\" three times!"
答案 0 :(得分:7)
我认为公共语言StringUtils可以做到这一点
http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringEscapeUtils.html