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 s)
quote
return "'" + s.replace("'", "''").replace("&", "&amp;").replace("<", "&lt;") + "'";
Stringquote(String s)
quote
int slashEIndex = s.indexOf("\\E");
if (slashEIndex == -1)
    return "\\Q" + s + "\\E";
StringBuffer sb = new StringBuffer(s.length() * 2);
sb.append("\\Q");
slashEIndex = 0;
int current = 0;
while ((slashEIndex = s.indexOf("\\E", current)) != -1) {
...
Stringquote(String s)
Wrap the given string in quotation marks.
return "\"" + s + "\"";
Stringquote(String s)
returns a quoted version of s with all internal quotes escaped
String escaped = s.replaceAll("\\\"", "\\\\\"");
return "\"" + escaped + "\"";
Stringquote(String s)
quote
if (s.indexOf(' ') >= 0) {
    char dqc = '"', sqc = '\'';
    int len = s.length();
    if (s.charAt(0) == dqc && s.charAt(len - 1) == dqc)
        return s;
    if (s.charAt(0) == sqc && s.charAt(len - 1) == sqc)
        return s;
    String qs = (s.indexOf(dqc) >= 0) ? "'" : "\"";
...
Stringquote(String s)
quote
return DOUBLE_QUOTE + s.replaceAll(UNESCAPED_DOUBLE_QUOTE, ESCAPED_DOUBLE_QUOTE) + DOUBLE_QUOTE;
Stringquote(String s)
Adds a pair of quotes ("x") if no quotes (" or ') are present.
if (s == null) {
    return null;
char startChar = s.charAt(0);
char endChar = s.charAt(s.length() - 1);
if ((startChar == '\'' || startChar == '"') && startChar == endChar)
    return s; 
else
...
Stringquote(String s)
Quotes the specified string, or returns "(null)" if it is null.
if (s != null) {
    String quoted = '"' + s + '"';
    return quoted;
} else {
    return "(null)";
Stringquote(String s, char ch)
quote
return !isQuoted(s, ch) ? ch + s + ch : s;
Stringquote(String s, String nullResult)
Returns a quoted version of a given string, i.e.
if (s == null) {
    return nullResult;
StringBuffer result = new StringBuffer();
result.append('"');
int length = s.length();
for (int i = 0; i < length; i++) {
    char c = s.charAt(i);
...