该函数会把指定文件中字串stxt替换为toTxt
procedure restr(fn: Ansistring
stxt, toTxt: string);
var
StrL, x, pos, fpos, num, readnum: integer;
buf: array[0..500] of char;
SFile: file;
L, H: char;
begin
StrL := Length(stxt);
AssignFile(sfile, fn);
reset(sfile, 1);
repeat
buf := #0;
Num := 0;
fpos := filepos(sfile);
blockread(sfile, buf, Sizeof(Buf), readnum);
repeat
Pos := num;
for x := 1 to StrL do begin
L := sTxt[x]
H := Buf[num];
if L = H then begin
inc(num);
if x = StrL then begin
seek(sfile, fpos + pos);
blockWrite(sfile, toTxt[1], Length(totxt));
end;
end
else begin
if x = 1 then inc(num);
break;
end;
end;
until num >= high(buf);
until readnum <= 0;
closefile(sfile);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Findstr('文件名', '003e2b6c3d', '53e2e6c3fs');
end;