Java Utililty Methods String Quote

List of utility methods to do String Quote

Description

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

Method

StringquoteString(String s)
Return a proper quoted string if the string contains the delimiter character
return quoteString(s, DELIMETER);
StringquoteString(String s)
quoteString
String quoteStr = s.trim();
if (!quoteStr.startsWith("'") && !quoteStr.endsWith("'")) {
    quoteStr = "'" + quoteStr + "'";
    return quoteStr;
return s;
StringquoteString(String s)
quote String
return "\"" + s + "\"";
StringquoteString(String s)
quote String
if (s == null || s.equals("null") == true) {
    return null;
return "\"" + s + "\"";
StringquoteString(String s)
Quote string and escape characters - ab'c -> 'ab''c'
if (s == null) {
    return null;
int len = s.length();
StringBuilder s2 = new StringBuilder(len + 2).append('\'');
for (int i = 0; i < len; i++) {
    char ch = s.charAt(i);
    s2.append(ch);
...
StringquoteString(String s)
quote String
assert s != null;
if (s.contains(" "))
    return new StringBuilder().append("\"").append(s.replace("\"", "\\\"")).append("\"").toString();
return s.replace("\"", "\\\"");
StringQuoteString(String source)
Quotes the string.
return '"' + source + '"';
StringquoteString(String source, char quote)
Quote a string so that it can be used as an identifier or a string literal in SQL statements.
StringBuffer quoted = new StringBuffer(source.length() + 2);
quoted.append(quote);
for (int i = 0; i < source.length(); i++) {
    char c = source.charAt(i);
    if (c == quote)
        quoted.append(quote);
    quoted.append(c);
quoted.append(quote);
return quoted.toString();
StringquoteString(String src)
Return a string in which all the quotable characters (tab, newline, ' and ", etc) are quoted, Java-style.
StringBuffer buf = new StringBuffer();
for (int i = 0; i < src.length(); i++) {
    char c = src.charAt(i);
    if (c == '\n')
        buf.append("\\n");
    else if (c == '\r')
        buf.append("\\r");
    else if (c == '\t')
...
StringquoteString(String str)
Wrap the given string with single quote.
if (null == str) {
    return str;
StringBuffer dstStr = new StringBuffer(str.length() + 2);
if (null != str) {
    dstStr.append("'").append(str).append("'");
return dstStr.toString();
...