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

StringunquoteHtmlContent(String x)
unquote Html Content
return unreplace(x, htmlOut, htmlIn);
StringunQuoteIdentifier(String identifier, boolean useAnsiQuotedIdentifiers)
Trims identifier, removes quote chars from first and last positions and replaces double occurrences of quote char from entire identifier, i.e converts quoted identifier into form as it is stored in database.
if (identifier == null) {
    return null;
identifier = identifier.trim();
String quoteChar = null;
if (identifier.startsWith("`") && identifier.endsWith("`")) {
    quoteChar = "`";
if (quoteChar == null && useAnsiQuotedIdentifiers) {
    if (identifier.startsWith("\"") && identifier.endsWith("\"")) {
        quoteChar = "\"";
if (quoteChar != null) {
    identifier = identifier.substring(1, (identifier.length() - 1));
    return identifier.replaceAll(quoteChar + quoteChar, quoteChar);
return identifier;
StringunQuoteIdentifier(String identifier, String quoteChar)
Trims identifier, removes quote chars from first and last positions and replaces double occurrences of quote char from entire identifier, i.e converts quoted identifier into form as it is stored in database.
if (identifier == null) {
    return null;
identifier = identifier.trim();
int quoteCharLength = quoteChar.length();
if (quoteCharLength == 0) {
    return identifier;
if (identifier.startsWith(quoteChar) && identifier.endsWith(quoteChar)) {
    String identifierQuoteTrimmed = identifier.substring(quoteCharLength,
            identifier.length() - quoteCharLength);
    int quoteCharPos = identifierQuoteTrimmed.indexOf(quoteChar);
    while (quoteCharPos >= 0) {
        int quoteCharNextExpectedPos = quoteCharPos + quoteCharLength;
        int quoteCharNextPosition = identifierQuoteTrimmed.indexOf(quoteChar, quoteCharNextExpectedPos);
        if (quoteCharNextPosition == quoteCharNextExpectedPos) {
            quoteCharPos = identifierQuoteTrimmed.indexOf(quoteChar,
                    quoteCharNextPosition + quoteCharLength);
        } else {
            return identifier;
    return identifier.substring(quoteCharLength, (identifier.length() - quoteCharLength))
            .replaceAll(quoteChar + quoteChar, quoteChar);
return identifier;
StringunQuoteIdentifier(String identifier, String quoteChar)
Trims identifier, removes quote chars from first and last positions and replaces double occurrences of quote char from entire identifier, i.e converts quoted identifier into form as it is stored in database.
if (identifier == null) {
    return null;
identifier = identifier.trim();
int quoteCharLength = quoteChar.length();
if (quoteCharLength == 0 || " ".equals(quoteChar)) {
    return identifier;
if (identifier.startsWith(quoteChar) && identifier.endsWith(quoteChar)) {
    String identifierQuoteTrimmed = identifier.substring(quoteCharLength,
            identifier.length() - quoteCharLength);
    int quoteCharPos = identifierQuoteTrimmed.indexOf(quoteChar);
    while (quoteCharPos >= 0) {
        int quoteCharNextExpectedPos = quoteCharPos + quoteCharLength;
        int quoteCharNextPosition = identifierQuoteTrimmed.indexOf(quoteChar, quoteCharNextExpectedPos);
        if (quoteCharNextPosition == quoteCharNextExpectedPos) {
            quoteCharPos = identifierQuoteTrimmed.indexOf(quoteChar,
                    quoteCharNextPosition + quoteCharLength);
        } else {
            return identifier;
    return identifier.substring(quoteCharLength, (identifier.length() - quoteCharLength))
            .replaceAll(quoteChar + quoteChar, quoteChar);
return identifier;
StringunquoteImpl(String s, char delim)
unquote Impl
if (s == null || s.length() < 2)
    return s;
if (!(s.charAt(0) == delim && s.charAt(s.length() - 1) == delim))
    return s;
if (s.length() == 2)
    return "";
s = s.substring(1, s.length() - 1);
StringBuffer sb = new StringBuffer(s.length());
...
StringunquotePath(String path)
Unquote a path if it has quote (") at the beginning or at the end of it.
if (path == null || path.length() == 0)
    return path;
if (path.charAt(0) == '"') {
    path = path.substring(1);
if (path.charAt(path.length() - 1) == '"') {
    path = path.substring(0, path.length() - 1);
return path;
StringunquoteS(String s)
Take a string delimited with single quotes and remove the delimiters.
return unquoteImpl(s, '\'');
StringunquoteString(final String input)
Removes quotes from a string.
if (input == null)
    throw new IllegalArgumentException("String cannot be null!");
return input.startsWith("\"") && input.endsWith("\"") || input.startsWith("'") && input.endsWith("'")
        ? input.substring(1, input.length() - 1)
        : input;
StringunquoteString(String s)
Unquote and unescape an HTTP quoted-string: http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2 Does nothing if s is not quoted.
if (s.startsWith("\"") && s.endsWith("\"")) {
    s = s.substring(1, s.length() - 1);
return s.replaceAll("\\\\(.)", "$1");
StringunquoteString(String s)
Unquote string and remove escape characters inside the script
if (s == null) {
    return null;
int len = s.length();
StringBuffer s2 = new StringBuffer(len);
for (int i = 0; i < len; i++) {
    char ch = s.charAt(i);
    char ch2 = (i < len - 1) ? s.charAt(i + 1) : 0;
...