Friday, 8 January 2016

Program to remove white spaces and special character from String in JAVA

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.


No comments:

Post a Comment