Java String Unescape unescape(String s)

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

Description

unescape

License

Apache License

Declaration

public static String unescape(String s) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String unescape(String s) {
        if (s.indexOf('\\') < 0)
            return s;

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < s.length(); i++) {

            char c = s.charAt(i);
            if (c == '\\' && i != (s.length() - 1)) {
                char c2 = s.charAt(i + 1);
                switch (c2) {
                case 'd':// dot
                    sb.append(".");
                    i++;/*from  ww  w. j a v a2s  . c o  m*/
                    break;
                case 's':// space
                    sb.append(" ");
                    i++;
                    break;
                case 'b':// back slash
                    sb.append("\\");
                    i++;
                    break;
                default:
                    throw new RuntimeException("failed to unescape string:" + s);
                }

            } else
                sb.append(c);

        }

        return sb.toString();
    }
}

Related

  1. unescape(String s)
  2. unescape(String s)
  3. unescape(String s)
  4. unescape(String s)
  5. unescape(String s)
  6. unescape(String s)
  7. unescape(String s)
  8. Unescape(String s)
  9. unEscape(String s)