Android String Case Convert toLowerSubset(String source, char substitute)

Here you can find the source of toLowerSubset(String source, char substitute)

Description

Returns a string with non alphanumeric chars converted to the substitute character.

License

Open Source License

Parameter

Parameter Description
source string to convert
substitute character to use

Return

converted string

Declaration

public static String toLowerSubset(String source, char substitute) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w  w  w. ja  v  a 2 s . c o  m
     * Returns a string with non alphanumeric chars converted to the
     * substitute character. A digit first character is also converted.
     * By sqlbob@users
     * @param source string to convert
     * @param substitute character to use
     * @return converted string
     */
    public static String toLowerSubset(String source, char substitute) {

        int len = source.length();
        StringBuffer sb = new StringBuffer(len);
        char ch;

        for (int i = 0; i < len; i++) {
            ch = source.charAt(i);

            if (!Character.isLetterOrDigit(ch)) {
                sb.append(substitute);
            } else if ((i == 0) && Character.isDigit(ch)) {
                sb.append(substitute);
            } else {
                sb.append(Character.toLowerCase(ch));
            }
        }

        return sb.toString();
    }
}

Related

  1. camelString(String str, boolean firstCharacterUppercase)
  2. firstByteToLower(String instring)
  3. capitalize(String plainMessage, char letter)
  4. uncapitalize(String capitalizedMessage, char letter)
  5. toUpper(char ch)
  6. UpperCase(String str)
  7. capitalize(String s)
  8. capitalize(final String str)
  9. capitalizeFirst(CharSequence movementTitle)