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?

[367 byte] By [TheNewLeadera] at [2007-11-27 4:10:01]
# 1
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?
corlettka at 2007-7-12 9:15:31 > top of Java-index,Java Essentials,Java Programming...
# 2

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?

TheNewLeadera at 2007-7-12 9:15:31 > top of Java-index,Java Essentials,Java Programming...
# 3
Where did you see String.isDigit(String) , this magic method ?I don't see this in Java API document.1) You could use Regular Expression to check2) Integer.parseInt()3) or more .....
rym82a at 2007-7-12 9:15:31 > top of Java-index,Java Essentials,Java Programming...
# 4
HI rym82i didnot see it any where that why i ws asking you how to do this
TheNewLeadera at 2007-7-12 9:15:31 > top of Java-index,Java Essentials,Java Programming...
# 5
hi, just look in Scanner API , you can also get answer there.It has many methods apart from nextToken() or hasNextToken().hope this helps..
gaurav_abbia at 2007-7-12 9:15:31 > top of Java-index,Java Essentials,Java Programming...
# 6
i'm using the string tiokenizer to get token then i want to check if this token is digit do nothingif it is string do somethingwhat is the method to check is digit for string
TheNewLeadera at 2007-7-12 9:15:31 > top of Java-index,Java Essentials,Java Programming...
# 7

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.

malcolmmca at 2007-7-12 9:15:31 > top of Java-index,Java Essentials,Java Programming...
# 8

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

TheNewLeadera at 2007-7-12 9:15:31 > top of Java-index,Java Essentials,Java Programming...
# 9
malcolmmccan you explain morehow can i tokenize the sentence then check if this token is integer?
TheNewLeadera at 2007-7-12 9:15:31 > top of Java-index,Java Essentials,Java Programming...