Java String Dequote dequoteString(String str)

Here you can find the source of dequoteString(String str)

Description

Removes matched quotes (single or double) from a string.

License

BSD License

Parameter

Parameter Description
str string to dequote

Return

the dequoted string or the original string, if no changes were made

Declaration

public static String dequoteString(String str) 

Method Source Code

//package com.java2s;
// Distributed under the OSI-approved BSD 3-Clause License.

public class Main {
    /**//from w w w.  j a  va2s  .  c  o m
     * Removes matched quotes (single or double) from a string. Quotes are only removed from the first and last
     * characters of the string.
     * 
     * @param str string to dequote
     * @return the dequoted string or the original string, if no changes were made
     */
    public static String dequoteString(String str) {
        if (str != null && str.length() > 1 && ((str.charAt(0) == '"' || str.charAt(0) == '\'')
                && str.charAt(str.length() - 1) == str.charAt(0))) {
            return str.substring(1, str.length() - 1);
        }
        return str;
    }
}

Related

  1. dequote(String value)
  2. dequoteFull(String str, char quote)
  3. dequoteIdentifier(String id)
  4. dequoteString(String s)
  5. dequoteString(String str)
  6. dequoteString(String strVal)
  7. deQuoteStringArray(String... quoted)