Question:
Program to remove special characters in the given string
Input: 1746%$10.
Output: 174610
Program:
import java.io.*;
public class LetUsCodeinJava{
public static void main(String[ ] args){
String inpStr = "1746%$10.";
inpStr = inpStr.replaceAll("[^0-9]","");
System.out.println(inpStr);
}
}
Output:
174610
Explanation:
In Java we have replaceAll( ) method to replace the sequence of matching characters with the matching regular expression and we can replace the string with whatever string.
Syntax:-
public String replaceAll(String regExpression, String repString)
0 comments:
Post a Comment