1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| procedure ExtractPhone(const SourceFileName, PhoneFileName: string);
const
PHONE_LEN = 10;
var
OffSets: TIntegerDynArray; // uses Types;
I: Integer;
StreamSrc, StreamDest: TFileStream;
gap: Integer;
Phone: string[PHONE_LEN];
begin
if SearchStringInBigFile(SourceFileName, 'PhoneNumber [228', OffSets, True, MaxInt, False, False) > 0 then
begin
gap := Length('PhoneNumber ['); // Si 228 inclu !
StreamSrc := TFileStream.Create(SourceFileName, fmOpenRead);
try
DeleteFile(PhoneFileName);
StreamDest := TFileStream.Create(PhoneFileName, fmCreate);
try
for I := Low(OffSets) to High(OffSets) do
begin
StreamSrc.Seek(OffSets[I] + gap, soBeginning);
StreamSrc.Read(Phone[1], PHONE_LEN);
StreamDest.Write(Phone[1], PHONE_LEN);
StreamDest.Write(BreakLine[1], Length(BreakLine)); // BreakLine: string = #13#10; existe dans delphi, je sais plus où
end;
finally
StreamDest.Free();
end;
finally
StreamSrc.Free();
end;
end;
end; |
Partager