I'm new to parsing (and new to Java), so I just want to be sure I'm conceptualizing this correctly.
I've written a program that allows the user to paste text into a text field, then click the "parse data" button. This button parses the text for two pieces of data: a name and a number.
The text data is generally pasted by the user in this form:
john 48915
beth 10431
frank 10112
anne 34887
taserface 90090
bill 56448
I'm using the regular expression "^\d+\t.*\d+$" to detect the pattern, and after the pattern is confirmed, my parse data code does the following:
Scanner parser = new Scanner(inputText);
parser.useDelimiter("\\n");
while (parser.hasNext()) {
String nextToken = parser.next();
String name = nextToken.trim();
// how do I get the number?
You'll notice the \n delimiter, which parses data at the new line character. This breaks the data up into rows, but does not break each row into two separate data points. I need to grab both the name and the number separately.
I believe I should be using a space delimiter, but I'm not sure if I should be doing this in one or two different steps. The confusion, I believe, stems from my limited understanding of how the Scanner does its work. But after a review of the Java documentation, I'm still not really sure.
Current output:
john 48915
beth 10431
frank 10112
etc.
Expected output:
john
48915
beth
10431
etc.
Should I be doing two different loops of parsing, or can I get the work done in the same pass?