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 string)
quote String
return "'" + escapeQuote(string) + "'";
StringquoteString(String strVal)
Replaces all newlines and carriage returns within the given string value with the corresponding html/xml expression
String newStr = strVal;
newStr = strReplace(newStr, "\r", "
"); 
newStr = strReplace(newStr, "\n", "
"); 
return newStr;
StringquoteString(String t)
quote String
return "\"" + escapeString(t, true, false) + "\"";
StringquoteString(String unquoted)
quote String
if (unquoted == null)
    return "null";
StringBuilder b = new StringBuilder(unquoted.length() + 2);
b.append('"');
for (int i = 0; i < unquoted.length(); ++i) {
    char c = unquoted.charAt(i);
    if (c == '"' || c == '\\')
        b.append('\\');
...
StringquoteString(String value, boolean force)
Returns the MIME type parameter value as either an HTTP token or HTTP quoted-string depending on whether or not it contains any characters that need to be escaped.
StringBuffer sb = new StringBuffer();
int len = value.length();
boolean didEscape = false;
for (int i = 0; i < len; i++) {
    char ch = value.charAt(i);
    if (isHttpCtlChar(ch) || isHttpSeparatorChar(ch)) {
        sb.append('\\');
        didEscape = true;
...
StringquoteStringLiteral(String string)
Quote a string so that it can be used as a string literal in an SQL statement.
return quoteString(string, '\'');
StringquoteStringSQL(String s)
Convert a string to a SQL literal.
if (s == null) {
    return "NULL";
int length = s.length();
StringBuilder buff = new StringBuilder(length + 2);
buff.append('\'');
for (int i = 0; i < length; i++) {
    char c = s.charAt(i);
...
StringquoteStringSQL(String s)
Convert a string to a SQL literal.
if (s == null) {
    return "NULL";
int length = s.length();
StringBuilder buff = new StringBuilder(length + 2);
buff.append('\'');
for (int i = 0; i < length; i++) {
    char c = s.charAt(i);
...
StringquoteStringValue(String value)
Quotes the string value if it contains spaces.
if (value == null)
    return null;
boolean isSpc = false;
for (int i = 0, len = value.length(); i < len; ++i) {
    if (Character.isSpaceChar(value.charAt(i))) {
        isSpc = true;
        break;
if (isSpc) {
    StringBuilder buf = new StringBuilder(value.length() + 2);
    buf.append(QUOTE).append(value).append(QUOTE);
    return buf.toString();
return value;
StringquoteText(String text)
quote Text
String txt = text.replaceAll("\n", "\\\\n");
txt = txt.replaceAll("\r", "\\\\r");
txt = txt.replaceAll("\t", "\\\\t");
return "\"" + txt + "\"";