JAVA Program to remove white spaces and special characters from String:
public class testRegular {
public static void main(String[] args) {
String text = "This - word ! has \\ /allot # of % special % characters ? this12340 _ ASGHJKK \t";
text = text.replaceAll("[^a-zA-Z0-9]", "");
System.out.println(text);
}}
Here it will remove everything except alphabets [ small and capital ] and digits [ 0 - 9].
Similarly, we can make our permutation and combination of arrangements in replaceAll method.
public class testRegular {
public static void main(String[] args) {
String text = "This - word ! has \\ /allot # of % special % characters ? this12340 _ ASGHJKK \t";
text = text.replaceAll("[^a-zA-Z0-9]", "");
System.out.println(text);
}}
Here it will remove everything except alphabets [ small and capital ] and digits [ 0 - 9].
Similarly, we can make our permutation and combination of arrangements in replaceAll method.
No comments:
Post a Comment