Reading info from text file...
Quote:
>I have a program that I've been working on now and then that finds the '%'
>character and then reads in the lines until another '%' character is
reached. In
>the past, I had my program just read in each line and
>immediately display it to the screen. Now, I'd like to give the user the
choice
>of either displaying only to the screen or write the lines to a specific
text
>file. I could just setup a few boolean variables and test the condition
before
>each writeln but I'd rather load up an array or something and have one read
>procedure with two distinct output procedures called based on one or two
boolean
>variables.
.............. snip ......................
Although you have had a lot of responses from your request, here is the
framework I have used on several occasions for similar actions. By using
BlockRead you can dump 60,000+ chars into an array very rapidly. That char
array has all the carrage returns ( CR = Chr(13) ) and line feeds ( LF =
Chr(10) ) as well as readable chars. Modifcations can be made but for my
purposes (addresses, bibliographies and personal help files) 60K is more
than enough. If you display all that at once that would be at least 30
screens.
These end of line chars can be used with another char to recognize the
beginning and ending of the section of text you select:
"[" + CR + LF (this represents a sequence of array chars)
This is the first chars of the text item.....
....and so on to last line of the item which ends with CR LF
"]" (on the line following)
The square brackets are my choice because they are easily remembered and
normally, [ is not at the end of a line nor ] at the beginning. In addition
you can just use ][ between text items. You can also put remarks and
references between ends and starts without interfering with the program.
To scan the array for a match I use tag:String[3] as a kind of char stack by
setting tag := '' and, within the loop reading the array chars, use:
tag := A[ct] + tag;
This will keep putting the array chars at the tag front and pushing the
third off the string. This makes the tag appear in the reverse order of
reading. In your CONST delarations you can do something like:
CONST LF = Chr(10); CR = Chr(13);
go = LF + CR + '['; stop = ']' + LF + CR;
and compare tag to go and stop.
Make two index arrays or one 2D array to store the array positions for start
and finish of each item of text such as indx[1..100, 1..2] of Word;
By making the first line of the text item descriptive, you can make a
numerical menu which displays just the first line by stopping after the
first LF. You can select by number (which is also the array primary index)
to view the item as well as to copy the text to another file with
BlockWrite.
This is enough for the general interest. I'll email some on hand source code
later.