: I need to search through a file looking for a certain code (this is a hospital Equipment program) and when that code is found, replace the records after it with differant ones.
:
: an example code would be WC-J-01. when this is found, i need to replace the rest of the record with different data. the file is a text file, and is already open. pleeze help... nobody else in my class has a clue (including the teacher)---
:
Th $pam $0ng
:
: $pam $pam whoever U may B,
: i M the lord of the $pam said he,
: and i'll spam U all whoever U may B,
: And i'll spam 4 all of my life said he.
:
If the record is on one line it is easy:
var
inf,outf:text;
line:string;
begin
Assign(inf,'infilename');
Reset(inf);
Assign(outf,'outfilename'); { <> infilename }
rewrite(outf);
while not eof(inf) do begin
readln(inf,line);
if Pos(SearchCode,line)>0 then begin
{ has found the code -> change the contents of LINE }
end; { else hasn't found the code -> do nothing }
writeln(outf,line);
end;
close(inf);
close(outf);
end;
If the records are spread over several lines. Then change the code in such a way, that the whole record is read and then rewritten. Example:
var
inf,outf:text;
recordlines:array[1..5] of string;
i:integer;
begin
Assign(inf,'infilename');
Reset(inf);
Assign(outf,'outfilename'); { <> infilename }
rewrite(outf);
while not eof(inf) do begin
for i:=1 to 5 do
readln(inf,recordlines[i]);
if Pos(SearchCode,recordlines[1])>0 then begin
{ has found the code -> change the contents of LINE }
end; { else hasn't found the code -> do nothing }
for i:=1 to 5 do
writeln(outf,recordlines[i]);
end;
close(inf);
close(outf);
end;
Good luck