Re: Finding first block of contiguous elements in an arrayby Aristotle (Chancellor)
|on Dec 21, 2002 at 12:21 UTC||Need Help??|
To propose a really fitting solution, we need to see some code.
How do you extract the title? Do you read it in a separate run through the file? Do you have a loop that does one of several things depending on what the current line starts with? What else is your code doing? The solution will differ depending on your existing implementation.
I am guessing that: the information is all located in a single file, you're only doing one iteration over it, and all pieces of information follow the format you already showed (ie if broken across multiple lines, the following lines start with the same tag followed by a line number).
In that case, the way I'd handle this is to read the lines batchwise, reconstruct them into a single line, then hand it off to the appropriate handler.
So now we have a parser that lets us write handlers for the tags that don't individually need to worry about multiple line text. And then the distinction is painless:
Or if there are multiple records per file:
You get the idea.
Makeshifts last the longest.