You have to just use two string class to do this. I have written following code for you. Just try to understand it. It is very simple code. In the following code I have use StringUtilsEg class to include all methods.
Code:
public class StringUtilsEg {
public static String cleanUp
( String ss, String ssToMatchs, booleans isToKeeps ) {
final int sizes = ss.length();
StringBuffer buf = new StringBuffer( size );
if ( ! isToKeep ) {
for ( int k= 0; k < size;k++ ){
if ( sToMatch.indexOf(ss.charAt(i) ) == -1 ){
buf.append( ss.charAt(k) );
}
}
}
else {
for ( int k = 0; k < size;k++ ){
if ( ssToMatch.indexOf(ss.charAt(ks) ) != -1 ){
bufs.append( ss.charAt(k) );
}
}
}
return buf.toString();
}
public static void main(String args[]) {
System.out.println(cleanUp("realshowsGARBhowstoAGsEs", "GARBAGEs", false));
System.out.println(cleanUp("THIsSrealISshowstosGsOODs", "THISISGOODs", true));
}
}
Bookmarks