Java String Unescape unescape(String str)

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

Description

unescape

License

Open Source License

Declaration

public static String unescape(String str) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007 Business Objects Software Limited and others.
 * All rights reserved. //  w  ww  .  j ava  2s  .c o  m
 * This file is made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Business Objects Software Limited - initial API and implementation
 *******************************************************************************/

public class Main {
    public static String unescape(String str) {
        StringBuffer sb = new StringBuffer(str.length());
        char[] array = str.toCharArray();
        for (int cnt = 0; cnt < array.length; cnt++) {
            if (array[cnt] != '\\') {
                sb.append(array[cnt]);
            } else {
                switch (array[++cnt]) {
                case 'n':
                    sb.append('\n');
                    break;

                case '\\':
                    sb.append('\\');
                    break;

                case 'r':
                    sb.append('\r');
                    break;

                default:
                    break;
                }
            }
        }

        return sb.toString();
    }
}

Related

  1. unescape(String str)
  2. unescape(String str)
  3. unescape(String str)
  4. unescape(String str)
  5. unescape(String str)
  6. unescape(String str)
  7. unescape(String str)
  8. unescape(String str)
  9. unescape(String str, char escapeChar, char[] targetChars, char[] escapedChars)