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

booleanquoteCharPresent(String quote)
quote Char Present
return !quote.equals("");
StringquoteComma(String value)
quote Comma
return value.replace(",", "\\,");
StringquoteCommandArgument(String s)
quote Command Argument
return new StringBuilder(s.length() + 2).append("\"").append(s).append("\"").toString();
StringquoteComments(String value)
quote Comments
char[] chars = value.toCharArray();
if (!commentProvided(chars)) {
    return null;
StringBuilder builder = new StringBuilder();
int prev = 0;
for (int i = 0; i < chars.length; i++) {
    if (chars[i] == 0x00) {
...
StringquoteContentsOfNextBracket(String piece)
quote Contents Of Next Bracket
if (piece.trim().isEmpty()) {
    return "";
int openBracket = openBracket(piece, 0);
if (openBracket < 0) {
    return piece;
int closeBracket = closeBracket(piece, openBracket + 1);
...
StringquoteCSV(Object val)
Double quotes input string for CSV if needed: string contains ", \n, \r, ','
if (val == null) {
    return "";
} else if (val instanceof String) {
    return quoteCSVStr((String) val);
return val.toString();
StringquoteCSVValue(String value, String sep)
Quotes a value in CSV format converter.
if (value == null) {
    return null;
} else if (value.length() == 0) {
    return QUOTE + QUOTE;
value = value.replaceAll(QUOTE, QUOTE + QUOTE);
boolean needQuote = false;
needQuote = (value.indexOf(sep) != -1) || (value.indexOf(QUOTE) != -1) || (value.indexOf('\n') != -1) 
...
CharSequencequoted(CharSequence s)
quoted
final StringBuilder r = new StringBuilder();
r.append('"');
for (int i = 0; i < s.length(); ++i) {
    switch (s.charAt(i)) {
    case '\b':
        r.append("\\b");
        break;
    case '\n':
...
CharSequencequoted(CharSequence s)
quoted
final StringBuilder r = new StringBuilder();
for (int i = 0; i < s.length(); ++i) {
    char c = s.charAt(i);
    if (Character.isWhitespace(c) || c == '\\')
        r.append('\\');
    r.append(c);
return r.toString();
...
Stringquoted(final String str)
quoted
final StringBuffer buf = new StringBuffer(str);
for (int i = buf.length() - 1; i >= 0; --i)
    switch (buf.charAt(i)) {
    case '\'':
    case '\\':
        buf.insert(i, '\\');
return buf.toString();
...