Java String Unquote unquote(String quoted)

Here you can find the source of unquote(String quoted)

Description

Removes the first and last single or double quotes (if they exist).

License

Open Source License

Declaration

public static String unquote(String quoted) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2009 Oracle. 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.
 * /*from www. j  a va2  s  .c  om*/
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/

public class Main {
    /**
     * Removes the first and last single or double quotes (if they exist).
     */
    public static String unquote(String quoted) {
        if (quoted != null && quoted.length() >= 2) {
            int len = quoted.length();
            char firstChar = quoted.charAt(0);
            char lastChar = quoted.charAt(len - 1);
            if (firstChar == lastChar && (firstChar == '\'' || firstChar == '"')) {
                return quoted.substring(1, len - 1);
            }
        }
        return quoted;
    }
}

Related

  1. unquote(String maybeQuoted)
  2. unquote(String message)
  3. unquote(String name)
  4. unquote(String name)
  5. unquote(String quoted)
  6. unquote(String quoted)
  7. unquote(String quotedString)
  8. unquote(String s)
  9. unquote(String s)