Reading in Multiple Coordinates on one line (Java)
I'm having an issue reading in a multiple set of of values that will be
saved as x,y coordinates and then stored as nodes. I am writing this
program in Java. Some input lines from a text file looks like this:
(220 616) (220 666) (251 670) (272 647) # Poly 1
(341 655) (359 667) (374 651) (366 577) # Poly 2
(311 530) (311 559) (339 578) (361 560) (361 528) (336 516) # Poly 3
I need to read in each of these coordinates and store them as a node in
the format node(x,y). What is the best way to accomplish this? So far I am
using a scanner that reads the input file while there is a next line. I
save the line in a string s and am trying to parse it like so
while (scanner.hasNextLine()) {
String s = nextLine();
//parse code goes here
}
I've read several posts above delimiters but I'm still a bit lost.
Essentially I need to be able to loop through and save each x,y coordinate
as a node that I will then be storing in an array.
Any help helps! Thanks!
No comments:
Post a Comment