Java String Unescape unescapeString(String s)

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

Description

unescape String

License

Open Source License

Declaration

public static String unescapeString(String s) 

Method Source Code

//package com.java2s;
/**/* w  ww.j a v a  2  s . co  m*/
 * Copyright (c) 2011, 2014 Eurotech and/or its affiliates
 *
 *  All rights reserved. This program and the accompanying materials
 *  are 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:
 *   Eurotech
 */

public class Main {
    public static String unescapeString(String s) {
        String value = s;

        // remove all space at the beginning of the string which are not escaped
        value = value.replaceAll("^((?<!\\\\) )*", "");

        // remove all space at the end of the string which are not escaped
        value = value.replaceAll("((?<!\\\\) )*$", "");

        // replace all escaped spaces with just space
        // The pattern covers for any even number of backslashes before the space char
        value = value.replaceAll("\\\\(\\\\\\\\)* ", " ");

        // replace all escaped comma with just comma
        // The pattern covers for any even number of backslashes before the comma char
        value = value.replaceAll("\\\\(\\\\\\\\)*,", ",");

        return value;
    }
}

Related

  1. unEscapeString(String input)
  2. unescapeString(String input)
  3. unescapeString(String oldstr)
  4. unescapeString(String s)
  5. unescapeString(String s)
  6. unescapeString(String s, char enclosed)
  7. unEscapeString(String str)
  8. unEscapeString(String str)
  9. unescapeString(String str)