By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,737 Members | 1,971 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,737 IT Pros & Developers. It's quick & easy.

String to Integer Checking

P: n/a
I have a string in a variable, but I want to check if this string is a
group of characters or actually an integer/double/etc..

Any idea how this should be done??

Libra Blue
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
SPG
try this:
private boolean isNumeric(String checkStr){

try{
Integer.parseInt(checkStr);
return true; //Did not throw, must be a number
}catch(NumberFormatException err){
return false; //Threw, So is not a number
}
}

Suppose you could do same with Double, Float etc

Steve

"Libra Blue" <li********@hotmail.com> wrote in message
news:7f**************************@posting.google.c om...
I have a string in a variable, but I want to check if this string is a
group of characters or actually an integer/double/etc..

Any idea how this should be done??

Libra Blue

Jul 17 '05 #2

P: n/a
Thanks a lot

Libra Blue

"SPG" <st*******************@nopoo.blueyonder.co.uk> wrote in message news:<xT********************@news-text.cableinet.net>...
try this:
private boolean isNumeric(String checkStr){

try{
Integer.parseInt(checkStr);
return true; //Did not throw, must be a number
}catch(NumberFormatException err){
return false; //Threw, So is not a number
}
}

Suppose you could do same with Double, Float etc

Steve

"Libra Blue" <li********@hotmail.com> wrote in message
news:7f**************************@posting.google.c om...
I have a string in a variable, but I want to check if this string is a
group of characters or actually an integer/double/etc..

Any idea how this should be done??

Libra Blue

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.