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

StringquoteJavaString(String s)
Convert a string to the Java literal and enclose it with double quotes.
if (s == null) {
    return "null";
return "\"" + javaEncode(s) + "\"";
StringquoteJavaString(String s)
Quotes a string literal for Java or JavaScript.
return s == null ? "null" : "\"" + s.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\\"", "\\\\\"") + "\"";
StringquoteJsonLib(String string)

from net.sf.json.util.JSONUtils

char b;
char c = 0;
int i;
int len = string.length();
StringBuffer sb = new StringBuffer(len * 2);
String t;
char[] chars = string.toCharArray();
char[] buffer = new char[1030];
...
StringquoteLiteralAsRegexp(String text)
quote Literal As Regexp
final int end = text.length();
StringBuilder sb = new StringBuilder(end + 8);
for (int i = 0; i < end;) {
    char c = text.charAt(i++);
    switch (c) {
    case ' ': 
    case '\t':
        while ((i < end) && text.charAt(i) <= ' ') {
...
StringquoteLocation(String location)
quote Location
if (location == null) {
    return null;
if (!location.startsWith("\"")) {
    location = "\"" + location;
if (!location.endsWith("\"")) {
    location = location + "\"";
...
StringquoteMdxIdentifier(String ident)
quote Mdx Identifier
return "[" + ident.replaceAll("]", "]]") + "]";
StringquoteMe(String unquoted)
quote Me
return "\"" + unquoted.replaceAll("\"", "\"\"").replaceAll("\\\\", "\\\\\\\\") + "\"";
StringquoteMeta(String s)
Quote all regular expression meta characters in s, in order to search for s literally.
int i = s.length() - 1;
StringBuffer bs = new StringBuffer("");
while ((i >= 0) && (s.charAt(i) == '\\')) {
    --i;
    bs.append("\\\\");
s = s.substring(0, i + 1);
return "\\Q" + s.replaceAll("\\\\E", "\\\\E\\\\\\\\E\\\\Q") + "\\E" + bs.toString();
...
Stringquotemeta(String s)
quotemeta
if (s == null) {
    throw new IllegalArgumentException("String cannot be null");
int len = s.length();
if (len == 0) {
    return "";
StringBuilder sb = new StringBuilder(len * 2);
...
StringquoteMonetDbIdentifier(String ident)
Quote and make the identifier MonetDB-proof by making lowercase and removing special characters.
ident = prepareMonetDbIdentifier(ident);
ident = "\"" + ident + "\"";
return ident;