Java String Unquote unquote(final String aInput)

Here you can find the source of unquote(final String aInput)

Description

Removes all double quotes from the given input.

License

Open Source License

Parameter

Parameter Description
aInput the input string to remove the quotes from, may be <code>null</code>.

Return

the unquoted version of the given input, or null if the original input was null.

Declaration

public static String unquote(final String aInput) 

Method Source Code

//package com.java2s;
/*//from  www. ja  v  a2  s. com
 * OpenBench LogicSniffer / SUMP project 
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 *
 * 
 * Copyright (C) 2010-2011 J.W. Janssen, www.lxtreme.nl
 */

public class Main {
    /**
     * Removes all double quotes from the given input.
     * 
     * @param aInput
     *          the input string to remove the quotes from, may be
     *          <code>null</code>.
     * @return the unquoted version of the given input, or <code>null</code> if
     *         the original input was <code>null</code>.
     * @see #unquote(String, char)
     */
    public static String unquote(final String aInput) {
        return unquote(aInput, '"');
    }

    /**
     * Removes all quotes, denoted by the given character, from the given input.
     * 
     * @param aInput
     *          the input string to remove the quotes from, may be
     *          <code>null</code>;
     * @param aQuoteChar
     *          the quote character to remove.
     * @return the unquoted version of the given input, or <code>null</code> if
     *         the original input was <code>null</code>. If the given input
     *         contained leading and/or trailing whitespace, it is removed from
     *         the result.
     */
    public static String unquote(final String aInput, final char aQuoteChar) {
        if (aInput == null) {
            return null;
        }

        final String quoteChar = Character.toString(aQuoteChar);

        String result = aInput.trim();
        if (result.startsWith(quoteChar) && result.endsWith(quoteChar)) {
            result = result.substring(1, result.length() - 1);
        }
        return result;
    }
}

Related

  1. unquote(char[] ca, int pos, StringBuffer out)
  2. unquote(final CharSequence quotePhrase)
  3. unquote(final String in)
  4. unQuote(final String quoted)
  5. unquote(final String s)
  6. unquote(final String str)