[fpc-pascal] Text scan in text files - (was: Full text scan - PDF files)

Tomas Hajny XHajT03 at hajny.biz
Tue Nov 2 11:02:18 CET 2010


On Mon, November 1, 2010 21:52, José Mejuto wrote:
 .
 .
> So if you are looking for ASCII words, use PDF2Text and use the POS
> function over the result:
>
> function HaveString(Filename: String; TheString: string): Boolean;
> var
>   F: TFileStream;
>   S: String;
>   AtPos: integer;
> begin
>   Result:=false;
>   F:=TFileStream.Create(Filename,fmOpenReadOnly);
>   SetLength(S,F.Size);
>   if F.Size>0 then
>   begin
>     F.ReadBuffer(S[1],F.Size);
>     AtPos:=Pos(UpperCase(TheString),S);
>     if AtPos>0 then
>       Result:=true;
>   end;
>   F.Free;
> end;

If I understand it correctly, this assumes reading the whole file into
memory at once. Depending on the size of that file and other conditions,
this may or may not be advisable...

Tomas





More information about the fpc-pascal mailing list