Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extracting INT value from a STRING

 
Brett Swift
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to figure out how to extract an int value from the command line. It came up in my head as something you'd think to be fundamental, but I can't figure it out!?!
I've tried parseInt(args[0]); valueOf(args[0]); but maybe I've got the syntax wrong. (not too familiar with those methods.. probably using them wrong!) Anyone have any tips? Thanks!
Brett
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pareInt is a static method of Integer, so just use this:

That should do the trick. Of course, you'll probably want to catch a NumberFormatException (which is a runtime exception) in the case that the first argument isn't a valid int.
Corey
 
Brett Swift
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks.. I now remember having this problem before and all it was ....was forgeting to reference the Integer class in front of the method call!
Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic