Class StringEscapeUtils


  • public class StringEscapeUtils
    extends Object
    Util class to manipulate String, especially around escape/unescape.
    • Constructor Detail

      • StringEscapeUtils

        public StringEscapeUtils()
    • Method Detail

      • unescapeJava

        public static String unescapeJava​(String str)

        Unescapes any Java literals found in the String to a Writer.

        This is a slightly modified version of the StringEscapeUtils.unescapeJava() function in commons-lang that doesn't drop escaped separators (i.e '\,').
        Parameters:
        str - the String to unescape, may be null
        Returns:
        the processed string
        Throws:
        IllegalArgumentException - if the Writer is null
      • escapeJava

        public static String escapeJava​(String str)

        Escapes the characters in a String using Java String rules.

        Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)

        So a tab becomes the characters '\\' and 't'.

        The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote must be escaped.

        Example:
         input string: He didn't say, "Stop!"
         output string: He didn't say, \"Stop!\"
         
        Parameters:
        str - String to escape values in, may be null
        Returns:
        String with escaped values, null if null string input
      • hex

        public static String hex​(char ch)

        Returns an upper case hexadecimal String for the given character.

        Parameters:
        ch - The character to convert.
        Returns:
        An upper case hexadecimal String