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

Stringquoted(String i, char q)
Surround a string in quotes.
StringBuffer b = new StringBuffer();
appendQuoted(b, i, q);
return b.toString();
Stringquoted(String path)
Useful for example for javac, which doesn't like file paths with spaces if they are not in double quotes.
path = path.replaceAll("\\\\", "\\\\\\\\");
path = path.replaceAll("\"", "\\\\\"");
return "\"" + path + "\"";
StringquoteD(String s)
Take a string and delimit it with double quotes.
return quoteImpl(s, '\"');
Stringquoted(String s)
Returns a String which equals the argument except that occurrences of '"' are expanded into its quoted-printable escaped equivalent sequence, '\"'.
if (s == null || s.indexOf('"') < 0)
    return s;
StringBuffer sb = new StringBuffer(s.length() + 5);
int i, start = 0;
while ((i = s.indexOf('"', start)) > -1) {
    sb.append(s.substring(start, i));
    sb.append("\\\"");
    start = i + 1;
...
booleanquoted(String str)
quoted
if (str.startsWith("\"") && str.endsWith("\"")) {
    return true;
if (str.startsWith("'") && str.endsWith("'")) {
    return true;
return false;
Stringquoted(String text)
quoted
return "'" + text.replaceAll("'", "''") + "'";
Stringquoted(String val, boolean wrap)
quoted
StringBuilder buf = new StringBuilder();
if (wrap)
    buf.append('"');
int l = val.length();
for (int n = 0; n < l; n++) {
    char c = val.charAt(n);
    if (c == '"')
        buf.append('\\');
...
Stringquoted(String value)
Returns the given value wrapped in double-quote characters (") if the value is not null, or the string "null" if it is null.
return value == null ? "null" : "\"" + value + "\"";
Stringquoted(String value, boolean addQuotes)
Returns a string in quotes for use in a database query.
if (value == null) {
    value = "NULL";
} else {
    value = value.replaceAll("'", "''");
    if (addQuotes) {
        value = "'" + value + "'";
return value;
StringquotedEscape(final String string)
Convenience method which quotes non null strings as well as escaping newlines, carriage returns and double quotes.
return null == string ? null : "\"" + escape(string) + "\"";