Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class StringLib {
- public static String deleteChars(String str, String filter){
- boolean[] searchA=new boolean[128];
- char[] strA=str.toCharArray();
- char[] filterA=filter.toCharArray();
- int src, dst;
- for (int i=0;i<128;i++)
- searchA[i]=false;
- for (char c: filterA)
- searchA[c]=true;
- int length=str.length();
- for (src=dst=0;src<length;src++){
- if (searchA[strA[src]]==false){
- strA[dst]=strA[src];
- dst++;
- }
- }
- return new String(strA, 0, dst);
- }
- public static void main(String[] args){
- String str="Hello there";
- String filter="aeiou";
- System.out.println("'"+str+"' filtered with '"+filter+"' gives: "+deleteChars(str, filter));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement