Java String Clean cleanString(String unallowableCharacters, String stringToClean)

Here you can find the source of cleanString(String unallowableCharacters, String stringToClean)

Description

This method will take a string of characters that you do not want to appear in your string.

License

BSD License

Parameter

Parameter Description
unallowableCharString --give me a string of all the chars you don't want in your final string.
stringToClean --this is the string that you want cleaned

Return

your new string

Declaration

public static String cleanString(String unallowableCharacters,
        String stringToClean) 

Method Source Code

//package com.java2s;
/*L/*  w  ww . jav  a 2 s  .c  om*/
 *  Copyright SAIC
 *
 *  Distributed under the OSI-approved BSD 3-Clause License.
 *  See http://ncip.github.com/i-spy/LICENSE.txt for details.
 */

public class Main {
    /**
     * This method will take a string of characters that you do not want to
     * appear in your string.  It will remove the unallowed characters and then
     * return to you the string as it would be without those characters.  For
     * instance if you passed ":" as the unallowed characters, and "I a:m ::Cle:an"
     * is the string you passed, you would end up with "I am Clean".  It does 
     * not replace the characters it removes them.
     * 
     * @param unallowableCharString --give me a string of all the chars you don't want in your
     * final string.
     * @param stringToClean  --this is the string that you want cleaned
     * @return  your new string
     */
    public static String cleanString(String unallowableCharacters,
            String stringToClean) {
        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;
    }

    /**
     * This method will take a char[] of characters that you do not want to
     * appear in your string.  It will remove the unallowed characters and then
     * return to you the string as it would be without those characters.  For
     * instance if you passed ':' as the unallowed characters, and "I a:m ::Cle:an"
     * is the string you passed, you would end up with "I am Clean".  
     * 
     * Important:It does not replace the characters it removes them.
     * 
     * @param unallowableCharString --give me a string of all the chars you don't want in your
     * final string.
     * @param stringToCheck  --this is the string that you want cleaned
     * @return  your new string
     */
    public static String cleanString(char[] unallowableCharArray,
            String stringToClean) {
        return cleanString(new String(unallowableCharArray), stringToClean);
    }
}

Related

  1. cleanString(String aString)
  2. cleanString(String field)
  3. cleanString(String input, char ol, char ne)
  4. cleanString(String statement)
  5. cleanStringArrayChar(String value)
  6. cleanStringByLikeWithHSQL(String input)
  7. cleanStringCamelCase(String in)
  8. cleanStringForFilename(String originalString)