check if this token is a digit
Hi all
if i have the following
name 30 CS 80 county 5555
after i did the stringTokenizer
i want to check
if the token is digit
then do nothing
else
do womething
but when i tried the
str.isDigit(str)
//where str is the string tokenz but i wont work
what is the reason?
any ideas?
ChookFollower,post you're code... and "but i wont work" is not a description of the problem is it?What have you tried, what results did you get, what else have you tried, etc, etc?
here is the code
while (st.hasMoreTokens()){
s=st.nextToken();
if(s.isDigit(s) == 0)
target += "0";
else
target += myencode(s) + "" ;
the error that i;m getting is
cannot find symbol method isDigit(java.lang.String)
any ideas?
I don't think you really mean "digit", since none of the fields in your example contain one digit. I take it what you mean is "is a valid integer". The simple way to test this is to use Integer.parseInt() to attempt to read it as an integer, then catch the NumberFormatException that parseInt throws if it isn't.
The isDigit() method is in Character, not String, and the parameter is a single character, not a String.
i found in the follwoing line
http://content.liferay.com/4.2/api/util-java/com/liferay/util/Validator.html#isDigit(char)
that isDigit work for char and String
isDigit
public static boolean isDigit(char c)
isDigit
public static boolean isDigit(java.lang.String s)
i will use what u suggest malcolmmc