Java String Unescape unescapeString(String escapedString)

Here you can find the source of unescapeString(String escapedString)

Description

Replaces all the printf-style escape sequences in a string with the appropriate characters.

License

Open Source License

Parameter

Parameter Description
escapedString the string containing escapes

Return

the string with all the escape sequences replaced

Declaration

public static String unescapeString(String escapedString) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  ww  w .jav  a 2s. c  o  m
     * Replaces all the printf-style escape sequences in a string
     * with the appropriate characters.
     * 
     * @param escapedString the string containing escapes
     * @return the string with all the escape sequences replaced
     */
    public static String unescapeString(String escapedString) {
        StringBuffer sb = new StringBuffer();
        for (int i = 1; i < escapedString.length() - 1; ++i) {
            char c = escapedString.charAt(i);
            if (c == '\\') {
                ++i;
                sb.append(unescapeChar(escapedString.charAt(i)));
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }

    private static char unescapeChar(char escapedChar) {
        switch (escapedChar) {
        case 'b':
            return '\b';
        case 't':
            return '\t';
        case 'n':
            return '\n';
        case 'f':
            return '\f';
        case 'r':
            return '\r';
        default:
            return escapedChar;
        }
    }
}

Related

  1. unEscape(String value)
  2. unescape(String value)
  3. unescape(String x)
  4. unescape(StringBuilder escapedText, int index)
  5. unEscapeString(final String src)
  6. unescapeString(String iccProfileSrc)
  7. unescapeString(String in)
  8. unescapeString(String inp)
  9. unescapeString(String input)