Re: How to search for a specific string in a txt file (FindComponent?)



<pjwolters@xxxxxxxxx> wrote in message
news:1114456563.484880.239940@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

> Can anyone tell me how to find a specific string in a txt file.
> I need to find this string and then change it into something else.
> I've tried using the FindComponent but no success.

I'm not surprised. FindComponent has exactly nothing to do with
searching text.

Type "Pos", press F1, read help.
Type "Delete", press F1, read more help.
Type "Insert", press F1, read yet more help.

Buy three, get one for free:

function LoadText(const Filename: String): String;
var Input: TStream;
begin
Input:=TFileStream.Create(Filename, fmOpenRead or fmShareDenyWrite);
try
SetLength(Result, Input.Size);
if (0<Length(Result))
then Input.ReadBuffer(Result[1], Length(Result));
finally
Input.Free;
end;
end;

Other implementations are possible.

Groetjes,
Maarten Wiltink


.



Relevant Pages

  • Re: Lock a File
    ... fmShareDenyWrite); ... The FileCreate function doesn't have a "mode" parameter, ... function FileCreate(const FileName: string; Mode: LongWord): Integer; ...
    (borland.public.delphi.nativeapi)
  • Re: Writing Binary Files with TFileStream
    ... var fid: Word; l: Byte; fieldid, value: String; FS: TFileStream; try ... fmOpenRead or fmShareDenyNone); tData.Clear; while do begin ...
    (comp.lang.pascal.delphi.misc)