Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two types of record in a text file

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I need to read a text file with the following content:

e 1 100m swimming
e 2 400m swimming
c 1 1 62000 Albert Chan
c 1 2 71000 Mary Rey
c 2 1 54000 David Lung

Here are two types of record, one is for an event (the first two lines) and the other is for competitor (the last three lines). e and c at the beginning is the indicator.

How can I read the record from the file line by line and then determine the type of it by the indicator. And then according to its type, read the fields into different variable?

I would appreciate any comment or suggestion, Thanks a lot.

Dante
dantetang@hkem.com
 
Hi!

Here is an example:

var
F: Text;
S: String;
begin
AssignFile(F, 'FILENAME.TXT');
{$I-}
Reset(F);
{$I+}
if IOResult=0 then begin
while not Eof(F) do begin
ReadLn(F, S);
if S[1]='c' then begin
{ handle the "competitor" line }
end
else begin
{ handle the "event" line }
end;
end;
CloseFile(F);
end;
end;

Good luck. Bye, Otto.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top