Java String Dequote deQuote(String s)

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

Description

Removes single or double quotes surrounding a string

License

Open Source License

Parameter

Parameter Description
s the string

Return

the string with the quotes removed

Declaration

public static String deQuote(String s) 

Method Source Code

//package com.java2s;
/*/*  w ww.j av a  2s  . c  o m*/
 * Copyright (c) 2004-2012 The YAWL Foundation. All rights reserved.
 * The YAWL Foundation is a collaboration of individuals and
 * organisations who are committed to improving workflow technology.
 *
 * This file is part of YAWL. YAWL is free software: you can
 * redistribute it and/or modify it under the terms of the GNU Lesser
 * General Public License as published by the Free Software Foundation.
 *
 * YAWL 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 Lesser General
 * Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with YAWL. If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Removes single or double quotes surrounding a string
     * @param s the string
     * @return the string with the quotes removed
     */
    public static String deQuote(String s) {
        if (!isNullOrEmpty(s)) {
            char first = s.charAt(0);
            if (first == '\'' || first == '"') {
                int last = s.lastIndexOf(first);
                if (last > 0) {
                    return s.substring(1, last);
                }
            }
        }
        return s;
    }

    public static boolean isNullOrEmpty(String s) {
        return s == null || s.isEmpty();
    }
}

Related

  1. dequote(final String in)
  2. deQuote(String in)
  3. dequote(String inputString)
  4. deQuote(String quotedString)
  5. dequote(String s)
  6. dequote(String str)
  7. dequote(String str)
  8. dequote(String str)