Java String Unescape unescape(String escaped)

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

Description

unescape

License

Open Source License

Declaration

public static String unescape(String escaped) 

Method Source Code

//package com.java2s;

public class Main {
    public final static char ESCAPE_CHAR = '\\';

    public static String unescape(String escaped) {
        boolean escaping = false;
        StringBuilder newString = new StringBuilder();

        for (char c : escaped.toCharArray()) {
            if (!escaping) {
                if (c == ESCAPE_CHAR) {
                    escaping = true;//from w w  w  . j  a  v a  2 s . c  o m
                } else {
                    newString.append(c);
                }
            } else {
                if (c == 'n') {
                    newString.append('\n');
                } else if (c == 'r') {
                    newString.append('\r');
                } else {
                    newString.append(c);
                }
                escaping = false;
            }
        }

        return newString.toString();

    }
}

Related

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