Strings 03 - Write a program to remove special characters from a string
Strings in Java - Program 03
➜ Program 03: Write a program to remove special characters from a string.
public class Test {
public static void main(String[] args) {
// Remove special characters
String str = "!@@#Hello @#%#$^#%^#% World123007^&*()";
System.out.println(str);
System.out.println(str.replaceAll("[^a-zA-Z0-9]", ""));
}
}
--------Output--------
!@@#Hello @#%#$^#%^#% World123007^&*() HelloWorld123007
-----------------------
!@@#Hello @#%#$^#%^#% World123007^&*() HelloWorld123007
-----------------------
Comments
Post a Comment