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;
/*//from  w ww .j  av  a2  s  . c o  m
 * Copyright 2013-2015 Technology Concepts & Design, Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    public static String unescape(String s) {
        if (s == null || s.length() == 0)
            return s;

        StringBuilder sb = new StringBuilder();
        char prev_ch = 0;
        for (int i = 0, len = s.length(); i < len; i++) {
            char ch = s.charAt(i);

            switch (ch) {
            case '\\':
                if (prev_ch == '\\')
                    sb.append(ch); // only keep backslashes that are escaped
                break;
            default:
                sb.append(ch);
                break;
            }

            prev_ch = ch;
        }

        return sb.toString();
    }
}

Related

  1. unescape(String quoted)
  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)