|
Author |
Topic: parsing line input (Read 226 times) |
|
kevinP
|
parsing line input
« on: Feb 16th, 2004, 10:11am » |
|
Hi, I'm doing some exercises out of Hill's book Computer Graphics using OpenGL. He demonstrates a simple program for reading in vertex points, two per line, from a file, and does this as simply as: inStream >> x >> y; This reads a line like "25 40" and fills both variables. Is there an easy way to do this in Java? To read a line with one number I ended up with: x = Integer.parseInt(reader.readLine()); But for two numbers per line I needed to do this: String pair[] = splitStrings(reader.readLine()); And then afterwards convert each to an integer. Is there a simpler way to do this?
|
Kevin Pfeiffer
|
|
|
toxi_ Guest
|
Re: parsing line input
« Reply #1 on: Feb 16th, 2004, 7:43pm » |
|
K, you could maybe use the splitInts() function instead of splitStrings(): Code:int pairs[] = splitStrings(reader.readLine()); |
|
|
|
|
|
kevinP
|
Re: parsing line input
« Reply #2 on: Feb 16th, 2004, 10:46pm » |
|
Of course! (I see now). I skipped over this possibility because I assumed that the "Ints" in splitInts() referred to the source and not the results. -K
|
Kevin Pfeiffer
|
|
|
|