Java String Unquote unquote(String text)

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

Description

removes single and double quotes around a string

License

Open Source License

Parameter

Parameter Description
text text to unquote

Return

unquoted text

Declaration

public static String unquote(String text) 

Method Source Code

//package com.java2s;
/***************************************************************************
 *                      (C) Copyright 2010 - Stendhal                      *
 ***************************************************************************
 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

public class Main {
    /**/*from   w  w  w .  j  a  v a2s.c om*/
     * removes single and double quotes around a string
     *
     * @param text text to unquote
     * @return unquoted text
     */
    public static String unquote(String text) {
        if ((text == null) || text.length() < 2) {
            return text;
        }

        if (text.charAt(0) == text.charAt(text.length() - 1)) {
            if (text.charAt(0) == '"' || text.charAt(0) == '\'') {
                return text.substring(1, text.length() - 1);
            }
        }
        return text;
    }
}

Related

  1. unquote(String string)
  2. unquote(String string)
  3. unquote(String string, char quote)
  4. unquote(String text)
  5. unquote(String text)
  6. unquote(String toUnquote, char quoteChar)
  7. unquote(String val)
  8. unquote(String val)
  9. unquote(String value)