We can go with String method using regex pattern to find the count of valid digits in a string Input.
Example:
public class Test {
public static void main(String[] args) {
String inputStr = "1234 Number count test example
using String method @@#@";
System.out.println("Digits
Count:"+(inputStr.length()-inputStr.replaceAll("[0-9]",
"").length()));
}
Output:
Digits Count:4
Comments
Post a Comment