
how to strip off unwanted characters from a string

Hi Friend,
Try this:
public class StripCharacters {
public String strip(String s) {
String st =" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
String result = "";
for ( int i = 0; i < s.length(); i++ ) {
if ( st.indexOf(s.charAt(i)) >= 0 )
result += s.charAt(i);
}
return result;
}
public static void main(String args[]) {
StripCharacters t = new StripCharacters();
System.out.println(t.strip("Hello **%$#)(World>"));
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.