checking string for digits
if i have a string is there a way to check that each character in the string is a digit
i know :
java.lang.Character.isDigit(stringX.charAt(3))
will show true if the 4th character (at position 3 in the index) is a digit
this is similar to what i want but the length of the string can be any size and im not sure how to check each character to see if its a digit if i dont know the size of the string
[431 byte] By [
chiasa] at [2007-11-27 3:55:39]

At least Long.parseLong, since that has a broader range. If you got a long phone number, parseint might fail. For some other numbers, parseLong maybe, too.
> Or you could place the Integer.parseInt method call
> inside a try/catch statement.
out of interest what is a try/catch method?
>Or a simple for loop over each character
if i did a loop, would it be something like:
int index = 0;
boolean found = false;
while (index < stringX.size() && !found)
{
String stringX = stringX.get(index);
if (java.lang.Character.isDigit(stringX))
{
found = true;
}
else
{
index++;
}
}
do u think thats right
(and thnx flounder for ur help in the other the topic)
>Why do people post code and ask us if it is correct?
>
>Better solution is to read the API and determine what parameters the methods take and what values they return. Or the very least try and compile it.
o ok, thats fair - sorry
Message was edited by:
chias
> > boolean containsOnlyNumeric =
> string.matches("\\d+");
>
> does this search a string of any size,
YES!
> for only
> digits and what class does this come under? string?
Yes 'String' but behind the scenes it uses the regular expression library java.util.regex.*.