Re: my dilemma -- hundreds of record types
- Posted by irv at take.maxleft.com Nov 15, 2002
- 425 views
On Friday 15 November 2002 04:30 pm, Chris wrote: > Thank you Irv. I'm confused over one thing though... > what if the data following the tag is several lines > long, as in a paragraph? How would I print the entire > data within the field, and stop when the program > reaches the next tag? Hi: One way would be to find the desired tag, then read lines until you hit the next < Of course, this won't work if there are < 's imbedded in the data field. -- tested object text --------------------------------- function LoadFile(sequence name) --------------------------------- integer fn object line fn = open(name,"r") text = {} while 1 do line = gets(fn) if atom(line) then exit else text = append(text,line) end if end while return text end function ----------------------------------------- function Extract(object tag, object text) ----------------------------------------- integer i object found found = "" i = 1 while i <= length(text) do -- iterate thru the buffer if match(tag,text[i]) then -- look for the <YEAR> tag found = text[i] -- store that line i += 1 --- go to next line while not match("<",text[i]) do -- look for < found &= text[i] -- if not there, add next line to buffer i += 1 -- go to next line end while else i += 1 end if end while return found end function -----------------------------[ MAIN ]------------------------------- text = LoadFile("test.txt") puts(1,Extract("<NAME>",text)) -- end Hope that helps Irv