Java Utililty Methods String Sanitize

List of utility methods to do String Sanitize

Description

The list of methods to do String Sanitize are organized into topic(s).

Method

StringsanitizeChatMessage(String message)
sanitize Chat Message
return message.replaceAll("(\\[|\\]|_|\\*|`)", "\\\\$1");
StringsanitizeClassname(String classname)
sanitize Classname
return classname.replace('.', '/').intern();
StringsanitizeClassName(String s)
Removes package names in instances where Class#getSimpleName() cannot be called, i.e.
return s.substring(s.lastIndexOf(".") + 1);
StringsanitizeColumn(String colName, String relationName)
sanitize Column
return colName.contains(".") ? colName : relationName + "." + colName;
StringsanitizeCompletion(String replace)
sanitize Completion
return replace == null ? null : replace.replaceAll(DOLLAR, ESCAPE_DOLLAR);
StringsanitizeDescription(String description)
sanitize Description
String prefix = "Maven GAV: ";
int i1 = description.indexOf(prefix);
if (i1 != -1) {
    int i2 = description.indexOf(" ", i1 + prefix.length());
    if (i2 != -1) {
        description = description.substring(0, i1) + description.substring(i2);
return description;
StringsanitizeDir(String name)
Takes a directory name and removes any illegal characters and shortens it to 64 characters if needed.
name = name.replaceAll("[\\\\/:*?\\\"<>|"
        + "\\x00-\\x1F]", 
        "");
name = name.trim();
if (name.length() > 64)
    name = name.substring(0, 64);
return name;
StringsanitizeFolderName(String s)
sanitize Folder Name
if (s == null)
    return null;
s = s.replace(":", "__");
s = s.replace("/", "__");
s = s.replace("\\", "__");
s = s.replace(" ", "__");
s = s.replace("[", "");
s = s.replace("]", "");
...
StringsanitizeForCmisName(String in)
sanitize For Cmis Name
if (null == in || in.isEmpty()) {
    return null;
in = in.replaceAll("[^a-zA-Z_0-9]", "_").replaceAll("_{2,}+", "_");
return in;
StringsanitizeForCsv(String str)
Sanitizes the string for comma-separated values (CSV) file output.
We follow the definition described by RFC 4180:
http://tools.ietf.org/html/rfc4180
return "\"" + str.replace("\"", "\"\"") + "\"";