The example of this article summarizes how the Java implementation finds numeric strings from strings. Share to everyone for your reference, specific as follows:
int start = 0;
String numstr = null;
for (int j = 0; J < valuesstr.length ()-1 J + +) {
if (Character.isdigit (Valuesstr.charat (j)) = = False
&&am P Character.isdigit (Valuesstr.charat (j + 1)) = = True) {
start = j + 1;
Numstr = valuesstr.substring (Start, valuesstr.length ());
}
}
There are also three ways to reprint from other places:
1. Functions with Java Self
public static Boolean isnumeric (String str) {for
(int i = Str.length ();--i>=0;) {
if (!) Character.isdigit (Str.charat (i))) {return
false;
}
}
return true;
}
2. Use regular expressions
public static Boolean isnumeric (String str) {pattern pattern
= Pattern.compile ("[0-9]*");
return Pattern.matcher (str). matches ();
3. With ASCII code
public static Boolean isnumeric (String str) {for
(int i=str.length ();--i>=0;) {
int chr=str.charat (i);
if (chr<48 | | chr>57) return
false;
}
return true;
}
I hope this article will help you with Java programming.