You are headed in the right direction.
Create an enum that contains at least these:
Name, Age, Unknown
You could call this enum 'LineType'.
As you read each line, you test the line for the keyword you are looking for (i.e. 'name', 'age'). As you encounter the keywords you could set a variable of the enum type that tells you what the next line value will be. Then on the next line read in the loop you take the value from the line and store that as the desired value.
One thing that will simplify this is to create a class to store the values you are going to pull out. As you encounter each new instance of data (new name) you can create a new instance of the class and add it to a collection/list.
One trick I use is to think backwards when you are working with loops. The best way to explain is to provide a little pseudo code:
for each line
what line was encountered last time around?
do the appropriate action based on linetype
what is the current line value?
assign line type based on keyword found
next line
The first pass thru the loop will also be linetype unknown so you'll just skip doing anything. But then you'll test for the keyword and start processing the lines on subsequent loops.
-
Peter