Java Utililty Methods String Clean

List of utility methods to do String Clean

Description

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

Method

StringcleanString(String aString)
Cleans a string, removing all ' ' and '\t'
StringBuffer lStringBuffer = new StringBuffer();
for (int lStringIndex = 0; lStringIndex < aString.length(); lStringIndex++) {
    if (aString.charAt(lStringIndex) != ' ' && aString.charAt(lStringIndex) != '\t') {
        lStringBuffer.append(aString.charAt(lStringIndex));
return lStringBuffer.toString();
StringcleanString(String field)
clean String
if (field == null)
    return null;
String cleanString = field.trim();
if (cleanString.equalsIgnoreCase(""))
    return null;
if (cleanString.equalsIgnoreCase("NULL"))
    return null;
if (cleanString != null && cleanString.length() == 0)
...
StringcleanString(String input, char ol, char ne)
Helper method for replacing the file seperator char based on the OS
return input.replace(ol, ne);
StringcleanString(String statement)
clean String
String newString = statement.trim();
for (int i = 0; i < REPLACEMENT_CHARS.length; i++) {
    newString = newString.replace(REPLACEMENT_CHARS[i], ' ').trim();
return newString;
StringcleanString(String unallowableCharacters, String stringToClean)
This method will take a string of characters that you do not want to appear in your string.
if (unallowableCharacters != null && stringToClean != null) {
    char[] filterString = unallowableCharacters.toCharArray();
    filterString = stringToClean.toCharArray();
    stringToClean = "";
    for (int i = 0; i < filterString.length; i++) {
        if (unallowableCharacters.indexOf(filterString[i]) == -1) {
            stringToClean = stringToClean.concat(Character.toString(filterString[i]));
return stringToClean;
StringcleanStringArrayChar(String value)
clean String Array Char
if (value.endsWith("]") && value.startsWith("[")) {
    int inizio = value.indexOf("[");
    int fine = value.indexOf("]");
    value = value.substring(inizio + 1, fine);
return value;
StringcleanStringByLikeWithHSQL(String input)
clean String By Like With HSQL
if (input == null) {
    return "";
input = input.replaceAll("\\\\", "\\\\\\\\\\\\\\\\");
input = input.replaceAll("'", "''");
input = input.replaceAll("%", "\\\\\\\\%");
input = input.replaceAll("_", "\\\\\\\\_");
return input;
...
StringcleanStringCamelCase(String in)
clean String Camel Case
String out = "";
if (in != null) {
    in = in.replaceAll("[-]", " ").replaceAll("[.]", " ").replaceAll("[/]", " ");
    String[] words = in.split(" ");
    for (String word : words) {
        out += toProperCase(cleanString(word));
return out;
StringcleanStringForFilename(String originalString)
clean String For Filename
String string = removeSpaces(originalString);
string = removeParens(string);
return string;
StringcleanStringForFilePath(final String dirty)
Cleans up an input String for use in file paths by removing trailing and leading whitespace, removing any chars that aren't a-z, A-Z or 0-9, replacing whitespace with underscores, and dropping the string to lowercase.
String clean = dirty;
if (clean != null) {
    clean = clean.replaceAll("\\s+", " "); 
    clean = clean.replaceAll("[^a-zA-Z0-9_ ]", ""); 
    clean = clean.trim(); 
    clean = clean.toLowerCase(); 
    clean = clean.replaceAll("\\s+", "_"); 
return clean;