aspose file tools*
The moose likes Java in General and the fly likes convert string chars to int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "convert string chars to int" Watch "convert string chars to int" New topic
Author

convert string chars to int

Patrick Mallahan
Ranch Hand

Joined: Apr 22, 2005
Posts: 69
i have a string of startDate = "2005/05/01" how would I take the 01 from the string and make it an int. I know Convert.ToInt works ............ I think.
Jeff Grant
Ranch Hand

Joined: Dec 19, 2001
Posts: 169
int temp = Integer.valueOf(startDate.substring(8,9));
Manuel Moons
Ranch Hand

Joined: Mar 05, 2002
Posts: 229
There are actually a lot of ways to parse out those numeric values.

An easy way is to get the value using the substring(int startpos,int endpos) method and then use Integer.parseInt(String value) method upon it. Be aware that a RuntimeException (NumberFormatException) is thrown by the parseInt method. If you do not catch it, it will throw an exception if the String does not hold a valid numeric value.
Edwin Keeton
Ranch Hand

Joined: Jul 10, 2002
Posts: 214

You can convert a String to an int like this:


SCJP, SCWCD
pendse anagha
Ranch Hand

Joined: Mar 09, 2005
Posts: 44
To add to it - ensure that you trim the string prior to making a call to "Integer.parseInt"

Thanks ,
-anagha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convert string chars to int