Hello,
I am having trouble when I read in a a file and parsing part of it as an int using substring.
Here is the code I have:
Basically I cant read in sPop. I know this is due to the fact that on some parts of the file there is white space in spaces 32-34. Im stumped on how to trim or omit this white space so I don't get an error. I have tried using .trim() but it doesn't work with integers.
Any help on this would be great. I have been searching on how to do this but cant seem to put it all together.
Thanks.
I am having trouble when I read in a a file and parsing part of it as an int using substring.
Here is the code I have:
Code:
String input = ""; while(readFile.hasNextLine()) { input = readFile.nextLine(); String sName = input.substring(0, 14); String sCap = input.substring(15,29); String sAbbr = input.substring(30,32); int sPop = Integer.parseInt(input.substring(32,40)); // breaks here String sReg = input.substring(40,55); int sRegNum = Integer.parseInt(input.substring(55,56)); sArray.insert(sName, sCap, sAbbr, sPop, sReg, sRegNum); }// end while
Any help on this would be great. I have been searching on how to do this but cant seem to put it all together.
Thanks.
Comment