Java String Unescape unescape(String s)

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

Description

unescape

License

Open Source License

Declaration

static String unescape(String s) 

Method Source Code

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

public class Main {
    static String unescape(String s) {
        if (s == null)
            return null;
        if (s.equals(""))
            return null;
        StringBuilder result = new StringBuilder(s.length());
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '\\') {
                if (i + 1 == s.length())
                    throw new IllegalArgumentException(
                            "The last character of the input may not be a \\!");
                i++;/*from  w  w w.ja  v a2  s  .  com*/
                char c = s.charAt(i);
                switch (c) {
                case 'n':
                    result.append("\n");
                    break;
                case 't':
                    result.append("\t");
                    break;
                case '\\':
                    result.append("\\");
                    break;
                case '"':
                    result.append("\"");
                    break;
                default:
                    throw new IllegalArgumentException(
                            "Unexpected escape sequence \\" + c + "!");
                }
            } else
                result.append(s.charAt(i));
        }
        return result.toString();
    }
}

Related

  1. unescape(String name)
  2. unescape(String oldStr)
  3. unescape(String original, char[] spec)
  4. unescape(String property)
  5. unescape(String quoted)
  6. unescape(String s)
  7. unEscape(String s)
  8. unescape(String s)
  9. unescape(String s)