Java Utililty Methods String Unquote

List of utility methods to do String Unquote

Description

The list of methods to do String Unquote are organized into topic(s).

Method

Stringunquote(String str)
unquote
assert isQuoted(str) : "Trying to unquote an unquoted string: " + str;
char qval = str.charAt(0);
str = str.substring(1, str.length() - 1);
if (qval == '\'') {
    str = str.replace("\\'", "'");
} else {
    assert qval == '"' : "Unknown quoted string format: " + str;
    str = str.replace("\\\"", "\"");
...
Stringunquote(String str)
Dequotifies a specified string.
int len = str.length();
StringBuffer buf = new StringBuffer(len);
boolean inQuotes = false;
char c;
int i = 0;
if (str.charAt(i) == '"') {
    inQuotes = true;
    i++;
...
Stringunquote(String str)
Returns the given quoted string without quotation marks.
int lastIndex = str.length() - 1;
if (lastIndex <= 0 || str.charAt(0) != '"' || str.charAt(lastIndex) != '"') {
    throw new IllegalArgumentException("Attempting to unquote string without quotes!");
return str.substring(1, lastIndex);
Stringunquote(String str)
unquote
if (str.length() >= 2) {
    if (str.startsWith("'") && str.endsWith("'")) {
        str = str.substring(1, str.length() - 1);
    } else if (str.startsWith("\"") && str.endsWith("\"")) {
        str = str.substring(1, str.length() - 1);
return str;
...
Stringunquote(String string)
unquotes are previously quoted string (but only if necessary), i.e., it removes the single quotes around it.
if (string.startsWith("'") && string.endsWith("'")) {
    string = string.substring(1, string.length() - 1);
    if ((string.contains("\\n")) || (string.contains("\\r")) || (string.contains("\\'"))
            || (string.contains("\\\"")) || (string.contains("\\\\")) || (string.contains("\\t"))
            || (string.contains("\\%")) || (string.contains("\\u001E"))) {
        string = unbackQuoteChars(string);
return string;
Stringunquote(String string)
Removes the double quotes at the beginning and the end of the given string.
if (string.length() >= 2) {
    if (string.charAt(0) == '\"') {
        if (string.charAt(string.length() - 1) == '\"') {
            if (string.charAt(string.length() - 2) != '\\') {
                return string.substring(1, string.length() - 1);
return string;
Stringunquote(String string)
unquote
if (string.length() > 1) {
    char firstChar = string.charAt(0);
    char lastChar = string.charAt(string.length() - 1);
    if ((firstChar == '"' && lastChar == '"') || (firstChar == '`' && lastChar == '`')) {
        return string.substring(1, string.length() - 1);
    return string;
} else {
...
Stringunquote(String string)
Remove quotes from the specified String , including single (') and double (") quotes.
string = string != null ? string.trim() : string;
return (string != null && ((string.startsWith("\"") && string.endsWith("\""))
        || (string.startsWith("'") && string.endsWith("'"))))
                ? string = string.substring(1, string.length() - 1)
                : string;
Stringunquote(String string)
unquotes are previously quoted string (but only if necessary), i.e., it removes the single quotes around it.
return unquote(string, "'");
Stringunquote(String string)
Ensure that the string is not surrounded by quotes.
if (string.startsWith("\"")) {
    string = string.substring(1);
if (string.endsWith("\"")) {
    string = string.substring(0, string.length() - 1);
return string;