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

StringcleanStringForJavaName(String original)
clean String For Java Name
if (original == null || original.isEmpty())
    return original;
char[] origChars = original.toCharArray();
char[] cleanChars = new char[origChars.length];
boolean isIdentifierStart = true;
for (int i = 0; i < origChars.length; i++) {
    char curChar = origChars[i];
    if (curChar != '$' && (isIdentifierStart ? Character.isJavaIdentifierStart(curChar)
...
StringcleanStringFromWhitespaces(String text)
clean String From Whitespaces
return text.replaceAll("&nbsp;", " ").trim();
StringcleanText(final String input)
Cleans a string for of insignificant whitespace
if (input == null)
    return "";
String retValue = input.replaceAll("\\r\\n|\\r|\\n|\\t", " ");
while (retValue.indexOf("  ") != -1)
    retValue = retValue.replaceAll("  ", " ");
return retValue;
StringcleanText(String s)
clean Text
s = s.trim();
int len = s.length();
StringBuffer cleanValue = new StringBuffer(len);
for (int i = 0; i < len; i++) {
    char ch = s.charAt(i);
    if (ch > 127) {
        System.out.println(
                "WARNING: Non ASCII character " + ch + " (" + (int) ch + ") in following string\n" + s);
...
StringcleanText(String s)
clean Text
return s.replaceAll("\\W", "");
StringcleanText(String t)
clean Text
t = t.replaceAll("(,|:|;)", " ");
t = t.replaceAll("  ", " ");
t = t.replaceAll("\\n", " ");
t = t.replaceAll("([\\.]\\s)", ".1. .0. ");
t = t.replaceAll("  ", " ");
t = t.replaceAll("   ", " ");
t = t.trim();
return t;
...
StringcleanText(String text)
Clean a string from left-over WikiMarkup (most parsers do not work 100% correct).
String plainText = text;
plainText = plainText.replaceAll("<.+?>", " ");
plainText = plainText.replaceAll("__.+?__", " ");
plainText = plainText.replaceAll("\\[http.+?\\]", " ");
plainText = plainText.replaceAll("\\{\\|.+?\\|\\}", " ");
plainText = plainText.replaceAll("\\{\\{.+?\\}\\}", " ");
plainText = plainText.replaceAll(" - ", " ");
plainText = plainText.replace('"', ' ');
...
StringcleanText(String text)
clean Text
if (text.startsWith("define ")) {
    text = text.substring(7, text.length());
return text;
StringcleanText(String text)
removes some non-standard characters from a string
if (text != null) {
    text = text.replaceAll("&AMP;", "&");
    text = text.replaceAll("_", " ");
    text = text.replaceAll("  ", " ");
return text;
StringcleanText(String text)
Cleans text so it can be shown properly.
return text.replaceAll("&amp;", "&");