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 quoted)
Removes the first and last single or double quotes (if they exist).
if (quoted != null && quoted.length() >= 2) {
    int len = quoted.length();
    char firstChar = quoted.charAt(0);
    char lastChar = quoted.charAt(len - 1);
    if (firstChar == lastChar && (firstChar == '\'' || firstChar == '"')) {
        return quoted.substring(1, len - 1);
return quoted;
Stringunquote(String quoted)
remove the surrounding quotation mark and restore 2 successive quotation marks to 1
String content = quoted;
if (quoted.indexOf("'") == 0 && quoted.lastIndexOf("'") == quoted.length() - 1 && quoted.length() > 1) {
    content = quoted.substring(1, quoted.length() - 1).replaceAll("''", "'");
} else if (quoted.indexOf("\"") == 0 && quoted.lastIndexOf("\"") == quoted.length() - 1
        && quoted.length() > 1) {
    content = quoted.substring(1, quoted.length() - 1).replaceAll("\"\"", "\"");
} else if (quoted.indexOf("[") == 0 && quoted.lastIndexOf("]") == quoted.length() - 1
        && quoted.length() > 1) {
...
Stringunquote(String quotedString)
unquote
if (quotedString == null)
    return quotedString;
if (quotedString.startsWith("\"") && quotedString.endsWith("\"")) {
    return quotedString.substring(1, quotedString.length() - 1);
return quotedString;
Stringunquote(String s)
Remove single or double quotes.
if ((s.startsWith("\"") && s.endsWith("\"")) || (s.startsWith("'") && s.endsWith("'")))
    s = s.substring(1, s.length() - 1);
return s;
Stringunquote(String s)
unquote
if (s.length() >= 6 && s.charAt(0) == s.charAt(1)) {
    s = s.replace('\u0000', '\n');
    return s.substring(3, s.length() - 3);
} else {
    return s.substring(1, s.length() - 1);
Stringunquote(String s)
Unquote the given string and replace escape sequences by the original characters.
char[] in = s.toCharArray();
char[] out = new char[in.length];
boolean inEscape = false;
int k = 0;
int n = in.length;
for (int i = 0; i < n; i++) {
    if (inEscape) {
        switch (in[i]) {
...
Stringunquote(String s)
unquote
StringBuilder buf = new StringBuilder();
int i = s.length();
boolean quoted = false, escaped = false;
for (int n = 0; n < s.length(); n++) {
    char c = s.charAt(n);
    if (n == 0 && c == '"') {
        quoted = true;
    } else if (!(quoted && n + 1 == i && !escaped && c == '"'))
...
Stringunquote(String s)
unquote
if (s == null || s.length() == 0)
    return s;
if (s.startsWith("\""))
    s = s.substring(1);
if (s.endsWith("\""))
    s = s.substring(0, s.length() - 1);
return s;
Stringunquote(String s)
unquote
if (s == null) {
    return "";
if (startsWith(s, "'")) {
    return unwrap(s, "'", "'");
} else if (startsWith(s, "\"")) {
    return unwrap(s, "\"", "\"");
return s.trim();
Stringunquote(String s)
Unquote a string.
if (s == null) {
    return null;
if (s.length() < 2) {
    return s;
char first = s.charAt(0);
char last = s.charAt(s.length() - 1);
...