[hotjoe.com] HotJoe Java Help Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Visit java.com
Please send email if you are having login problems - see the posts below for more info.
Hotmail and Yahoo! users - please see the Hotmail post or the Yahoo! post for information on lost emails.
Regarding String Validation  XML
Forum Index » New to Java
Author Message
arav5566

Newbie

Joined: 10/07/2009 01:07:08
Messages: 2
Offline

Hi,

In my program i am converting a string to a long. val is a string variable. when Long.parseLong(Val) executes it throws numberformat exception because val contains a string "COO" . I want to execute parselong function after checking if val is not a string. How do i check val is not having string value?

Regards,
Arav
stdunbar

Newbie
[Avatar]

Joined: 06/22/2005 14:51:37
Messages: 849
Location: Superior, CO, USA
Offline

I would do something like:



or something like that. This allows you to handle it just fine.

Thanks for using the forums at hotjoe.com
[WWW] [Yahoo!] [ICQ]
arav5566

Newbie

Joined: 10/07/2009 01:07:08
Messages: 2
Offline

Thanks a lot for the info. I don't want to get the Number format exception. I want to check whether the variable has string and do something. Is there any other way to do?
stdunbar

Newbie
[Avatar]

Joined: 06/22/2005 14:51:37
Messages: 849
Location: Superior, CO, USA
Offline

You could put the code I have into a method:



Another alternative is to walk through the String character by character and call Character.isDigit on each character. You'd have to specially check for the minus sign and a period (or comma if you're in a country that uses commas for decimal places).

Lastly, you could write a regular expression to check if the string. This is a bit harder but would work too.

Thanks for using the forums at hotjoe.com
[WWW] [Yahoo!] [ICQ]
 
Forum Index » New to Java
Go to:   
Powered by JForum 2.1.9 © JForum Team
This site run by Scott Dunbar of Xigole Systems. © 2005-2011 - Scott Dunbar
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners
hotjoe.com, xigole.com, and Scott Dunbar have no affiliation with Oracle