Java String Unescape unescape(String escaped, char escape)

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

Description

Opposite of #escape(String,char,char)

License

Open Source License

Parameter

Parameter Description
escaped a parameter
escape a parameter

Declaration

public static String unescape(String escaped, char escape) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//  w w w .  j a  v a 2 s.  c om
     * Opposite of {@link #escape(String, char, char)}
     * @param escaped
     * @param escape
     * @return
     */
    public static String unescape(String escaped, char escape) {
        StringBuilder sb = new StringBuilder(escaped.length());
        for (int i = 0, n = escaped.length(); i < n; i++) {
            char c = escaped.charAt(i);
            if (c == escape) {
                i++;
                c = escaped.charAt(i);
            }
            sb.append(c);
        }
        return sb.toString();
    }

    /**
     * Convenience for peeking at a character which might be beyond the end of
     * the sequence.
     * 
     * @param chars
     * @param i
     * @return the char at index i, if within range, or 0 otherwise.
     */
    public static char charAt(CharSequence chars, int i) {
        return i < chars.length() ? chars.charAt(i) : 0;
    }
}

Related

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