Java String Unescape unescape(String text)

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

Description

unescape

License

Open Source License

Declaration

static String unescape(String text) 

Method Source Code

//package com.java2s;
/*//from   ww w . j a  v a  2 s.  co m
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2016 Neil C Smith.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 3 for more details.
 *
 * You should have received a copy of the GNU General Public License version 3
 * along with this work; if not, see http://www.gnu.org/licenses/
 *
 *
 * Please visit http://neilcsmith.net if you need additional information or
 * have any questions.
 */

public class Main {
    static String unescape(String text) {
        if (!text.contains("\\")) {
            return text;
        }
        int len = text.length();
        StringBuilder sb = new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            char c = text.charAt(i);
            if (c == '\\') {
                i++;
                c = text.charAt(i);
                switch (c) {
                case 'n':
                    sb.append('\n');
                    continue;
                case 't':
                    sb.append('\t');
                    continue;
                case 'r':
                    continue;
                }
            }
            sb.append(c);
        }
        return sb.toString();
    }
}

Related

  1. unescape(String string)
  2. unescape(String string)
  3. unescape(String string, int escape)
  4. unescape(String text)
  5. unescape(String text)
  6. unescape(String text)
  7. unescape(String text)
  8. unescape(String theValue)
  9. unescape(String val)