Java String Unquote unquote(String literal)

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

Description

Removes all quotes at the beginning and ending of given string.

License

LGPL

Parameter

Parameter Description
text the content to unquote.

Return

the unquoted version of such content.

Declaration

public static String unquote(String literal) 

Method Source Code

//package com.java2s;
/**/*from   w  ww  .  j  a va 2  s. com*/
 * Converts a line of text into an array of lower case words using a
 * BreakIterator.wordInstance(). <p>
 *
 * This method is under the Jive Open Source Software License and was
 * written by Mark Imbriaco.
 *
 * @param text a String of text to convert into an array of words
 * @return text broken up into an array of words.
 */

public class Main {
    /**
     * Removes all quotes at the beginning and ending of given string.
     * @param text the content to unquote.
     * @return the unquoted version of such content.
     */
    public static String unquote(String literal) {
        String result = "";

        if ((literal != null) && (literal.length() > 0)) {
            if (literal.charAt(0) != '\"') {
                if (literal.charAt(0) != '\'') {
                    result = literal;
                } else {
                    if (literal.trim().length() > 0) {
                        result = literal.substring(1, literal.length() - 1);
                    }
                }
            } else {
                result = literal.substring(1, literal.length() - 1);
            }
        }

        return result;
    }
}

Related

  1. unquote(String argument)
  2. unquote(String aString)
  3. unquote(String entityName)
  4. unquote(String in)
  5. unquote(String input, char quoteChar)
  6. unquote(String maybeQuoted)
  7. unquote(String message)
  8. unquote(String name)
  9. unquote(String name)