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

StringsanitizeSuiteName(String name)
Returns a sanitized suite name suitable for inclusion in a XML report.
return name.replaceAll("[[\\p{Punct}][\\p{Space}]&&[^_.-]]", "-").replaceAll("[.]+$", "");
StringsanitizeTag(String s)
sanitize Tag
if (s.length() > MAX_TAG_LENGTH) {
    s = s.substring(s.length() - MAX_TAG_LENGTH);
return s;
StringsanitizeTextAsDomId(final String text)
sanitize Text As Dom Id
return text.toLowerCase().replace(" ", "-");
StringsanitizeTimezones(String s)
sanitize Timezones
return s.replaceAll("[\\+\\-]\\d\\d\\d\\d", "+0000");
StringsanitizeTokenString(final String tokenString)
Returns a "sanitized" version of the given token string suitable for sending to an APNs server.
return tokenString.replaceAll("[^a-fA-F0-9]", "");
StringsanitizeToLineFeed(CharSequence string)
sanitize To Line Feed
StringBuilder sb = new StringBuilder();
for (int i = 0, len = string.length(); i < len; i++) {
    char c = string.charAt(i);
    boolean legal = c == '\u0009' || c == '\n' || (c >= '\u0020' && c <= '\uD7FF')
            || (c >= '\uE000' && c <= '\uFFFD');
    if (legal) {
        sb.append(c);
return sb.toString();
longsanitizeToLong(String origMSISDN)
sanitize To Long
return Long.parseLong(sanitizeToString(origMSISDN));
StringsanitizeToString(String origMSISDN)
sanitize To String
origMSISDN = origMSISDN.trim();
return origMSISDN.startsWith("86") ? origMSISDN : "86" + origMSISDN;
StringsanitizeTypename(String name)
Rewrites a type name so that it can be executed in code.
return name.replace('$', '.');
StringsanitizeUnicode(String str)
sanitize Unicode
if (str == null) {
    return null;
StringBuilder buf = new StringBuilder();
int len = str.length();
for (int i = 0; i < len; i++) {
    char ch = str.charAt(i);
    if (Character.isHighSurrogate(ch) || Character.isLowSurrogate(ch)) {
...