9 Replies Latest reply: Feb 18, 2009 8:53 PM by 807588 RSS

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

    807588
      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