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

Stringquote(String toQuote, String specials, char quoteChar)
Quote special characters.
if (toQuote == null) {
    return "";
StringBuilder result = new StringBuilder();
char c;
boolean isSpecial;
for (int i = 0; i < toQuote.length(); ++i) {
    c = toQuote.charAt(i);
...
Stringquote(String txt)
quote
StringBuffer sb = new StringBuffer("");
sb.append(replace(replace(txt, "'", "&#39;"), "", "&apos;"));
return sb.toString();
Stringquote(String val)
Wrap the provided val String in double-quotes.
if (val == null)
    return "\"\"";
return "\"" + val + "\"";
Stringquote(String val)
quote
if (val != null && val.length() > 0) {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < val.length(); i++) {
        char ch = val.charAt(i);
        switch (ch) {
        case '\'':
            buffer.append("\\'");
            break;
...
Stringquote(String val, char quote)
Quote a string, escaping it into C/C++ style
StringBuffer buff = new StringBuffer();
buff.append(quote);
buff.append(escape(val, quote));
buff.append(quote);
return buff.toString();
Stringquote(String value)
Safely escape an arbitrary string as a JSON string literal.
StringBuilder toReturn = new StringBuilder("\"");
for (int i = 0; i < value.length(); i++) {
    char c = value.charAt(i);
    String toAppend = String.valueOf(c);
    switch (c) {
    case '\b':
        toAppend = "\\b";
        break;
...
Stringquote(String value)
Quote the given string; single quotes are escaped.
return quote(value, '\'');
Stringquote(String value)
Surrounds a value with quote characters that are not contained in the value itself.
String quoteChar = "\"";
if (value.contains(quoteChar)) {
    quoteChar = "\'";
if (value.contains(quoteChar)) {
    throw new IllegalArgumentException(
            String.format("Could not find quote char for expression: %s", value));
return String.format("%s%s%s", quoteChar, value, quoteChar);
Stringquote(String value)
quote
String toReturn = value;
if (value != null) {
    StringBuilder builder = new StringBuilder();
    builder.append("\"");
    builder.append(value);
    builder.append("\"");
    toReturn = builder.toString();
return toReturn;
voidquote(StringBuilder buf, String str)
Simple quote of a string, escaping where needed.
buf.append('"');
escape(buf, str);
buf.append('"');