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

StringquotePlainText(final String textContent)
quote Plain Text
return textContent.replaceAll("(?m)^", "> ");
StringquoteQuery(String query)
Return a quoted version of the query if the original query is not quoted
final int length = query.length();
if (length > 1 && query.charAt(0) == '"' && query.charAt(length - 1) == '"') {
    return query;
StringBuilder sb = new StringBuilder();
sb.append("\"").append(query).append("\"");
return sb.toString();
StringquoteReference(final String reference)
quote Reference
if (reference == null) {
    throw new NullPointerException();
final char[] referenceChars = reference.toCharArray();
if (isQuotingNeeded(referenceChars) == false) {
    return '[' + reference + ']';
return '[' + quoteString(reference) + ']';
...
StringquoteRegexMeta(final String input)
Encloses the input string into protective characters \Q und \E, thus disabling special meaning of regex meta chars like *, ?, ., etc.
return "\\Q" + input + "\\E";
StringquoteRegexMeta(String str)
Quote the characters in a String that have a special meaning in regular expression.
if (str == null)
    return null;
if (str.length() == 0) {
    return EMPTY_STRING;
int len = str.length();
StringBuilder buf = new StringBuilder(len + 5);
for (int i = 0; i < len; i++) {
...
StringquoteRemarkSQL(String sql)
In a string, replace block comment marks with /++ ..
while (true) {
    int idx = sql.indexOf("*/");
    if (idx < 0) {
        break;
    sql = sql.substring(0, idx) + "++/" + sql.substring(idx + 2);
while (true) {
...
StringquoteRemarkSQL(String sql)
In a string, replace block comment marks with /++ ..
sql = replaceAll(sql, "*/", "++/");
return replaceAll(sql, "/*", "/++");
StringquoteReplacement(String s)
quote Replacement
if ((s.indexOf('\\') == -1) && (s.indexOf('$') == -1))
    return s;
StringBuffer sb = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    if (c == '\\') {
        sb.append('\\');
        sb.append('\\');
...
StringquoteReplacement(String s)
quote Replacement
if (s.indexOf('\\') == -1 && s.indexOf('$') == -1) {
    return s;
int length = s.length();
StringBuffer sb = new StringBuffer(length + 10);
for (int i = 0; i < length; i++) {
    char c = s.charAt(i);
    if (c == '\\') {
...
Stringquotes(CharSequence stringToQuote)
Quotes the given string (eg.
return "'" + stringToQuote + "'";