Search code examples
javastringstring-literals

converting string to string literal


Possible Duplicate:
How would you convert a String to a Java string literal?

Is there a library function that takes a string and converts is into a corresponding string literal? Example:

Please say\ask "What?" three times! -> "Please say\\ask \"What?\" three times!"


Solution

  • I think commons lang StringUtils does that

    http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringEscapeUtils.html