Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to extract an integer or a float value from a String of characters

807588Feb 18 2009 — edited Feb 18 2009
Hi i have a problem getting to a float value within a string of characters..
for instance the string is
"numberItem xxxxxxxxx 700.0" (each x is a space..the forum wouldnt let me put normal spaces for some reason)


how do i store 700.0 in a float variable

remember the string is obtained from an inputfile

so far i got the program to store the inputfile data line by line in a String array..i tried tokenizing the string to get to the the float value but since i have mulitple spaces within my string, the token method only gets "numberItem" from the above String

This is all i have so far:

String c;
String Array[] =new String[g]; (i used a while loop to obtain g(the nubmer of lines in the file))
while((c=(cr.readLine()))!=null)
{
Array[coun]=c;
}


it would be reallllllllllllllllllllllllllllllllllllllly easy if there was a predefined method to extract numeric values from a string in java..

Edited by: badmash on Feb 18, 2009 5:50 PM

Edited by: badmash on Feb 18, 2009 5:50 PM

Edited by: badmash on Feb 18, 2009 5:55 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 18 2009
Added on Feb 18 2009
9 comments
1,172 views