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 string)
Like #unescape but removes the double quote characters ('\"'), if any, before unescaping the string.
int length = string.length();
if (length >= 2 && string.charAt(0) == '\"' && string.charAt(length - 1) == '\"') {
    return unescape(string, 1, length - 2);
} else {
    return unescape(string, 0, length);
Stringunquote(String string, char quote)
Remove any surrounding quotes from a string
if (string.length() >= 2 && string.charAt(0) == quote && string.charAt(string.length() - 1) == quote)
    return string.substring(1, string.length() - 1);
else
    return string;
Stringunquote(String text)
unquote
if (text.length() > 0 && text.charAt(0) == SINGLE_QUOTE && text.charAt(text.length() - 1) == SINGLE_QUOTE) {
    return text.substring(1, text.length() - 1);
return text;
Stringunquote(String text)
unquote
if (text.startsWith("\"") && text.endsWith("\"")) {
    return text.substring(1, text.length() - 2);
return text;
Stringunquote(String text)
removes single and double quotes around a string
if ((text == null) || text.length() < 2) {
    return text;
if (text.charAt(0) == text.charAt(text.length() - 1)) {
    if (text.charAt(0) == '"' || text.charAt(0) == '\'') {
        return text.substring(1, text.length() - 1);
return text;
Stringunquote(String toUnquote, char quoteChar)
Unquote special characters.
StringBuilder result = new StringBuilder();
char c;
boolean quoted = false;
for (int i = 0; i < toUnquote.length(); ++i) {
    c = toUnquote.charAt(i);
    if (quoted) { 
        if (c != '\n') {
            result.append(c);
...
Stringunquote(String val)
unquote
if (!(val.startsWith("'") || val.startsWith("\"")) || !(val.endsWith("'") || val.endsWith("\""))) {
    throw new RuntimeException("Invalid string value: " + val);
return val.substring(1, val.length() - 1);
Stringunquote(String val)
unquote
if ((val.startsWith("\"") && val.endsWith("\"")) || (val.startsWith("'") && val.endsWith("'"))) {
    return val.substring(1, val.length() - 1);
return val;
Stringunquote(String value)
Unquote the given string if it is quoted; single quotes are unescaped.
return unquote(value, '\'');
Stringunquote(String value)
Removes the first level of quotes and escapes from a string
if (value.startsWith("\"")) {
    if (value.endsWith("\"")) {
        value = unescapeString(value.substring(1, value.length() - 1));
    } else {
        throw new IllegalArgumentException(
                "String literal " + value + " is not properly closed by a double quote.");
return value;