Java String Unescape unescape(String escaped)

Here you can find the source of unescape(String escaped)

Description

Unescape all escape sequences in string (strip one level of backslashes).

License

Open Source License

Parameter

Parameter Description
escaped The string to unescape

Return

A string with one level of escaping backslashes stripped.

Declaration

public static String unescape(String escaped) 

Method Source Code

//package com.java2s;

public class Main {
    /**/* w  w w.  j a va  2 s  .co  m*/
     * Unescape all escape sequences in string (strip one level of backslashes).
     * An escape sequence always consists of two characters on the form "\ <anychar>".
     * @param escaped The string to unescape
     * @return A string with one level of escaping backslashes stripped.
     */
    public static String unescape(String escaped) {
        char[] source = escaped.toCharArray();
        char[] dest = new char[source.length];
        int j = 0;
        for (int i = 0; i < source.length; i++) {
            if ((source[i] != '\\') || (i > 0 && source[i - 1] == '\\')) {
                dest[j++] = source[i];
            }
        }
        return new String(dest, 0, j);
    }
}

Related

  1. unescape(String aValue)
  2. unescape(String data)
  3. unescape(String elt)
  4. unescape(String entry)
  5. unescape(String escaped)
  6. unescape(String escaped, char escape)
  7. unescape(String escapedMessage)
  8. unescape(String input)
  9. unescape(String input)