Link to home
Start Free TrialLog in
Avatar of Dinkleburger
Dinkleburger

asked on

Find a string in a Txt file

Hello from Dinkleburger

Listen carefully what i want to do? lol

i have a File hidden away in C:\Windows\Sytem\FILENAME.Txt

the file sometimes is blank and sometimes has many lines of words

one word in the file is    ABRACADABRA

QUESTION... I want a procedure to read the File at its location and then search for the word ABRACADABRA
if the word is found then return a result TRUE.
FALSE if not found

Because i am not a good programmer yet i want the complete code
many thanks in advance Dinkleburger
ASKER CERTIFIED SOLUTION
Avatar of Motaz
Motaz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nestorua
nestorua

HI,
Here one of the possibilities:
function IsMyWordThere(const MyWord, FileName: string): boolean;
begin
  Result:=False;
//
  if not FileExists(FileName)
   then EXIT;
//
  with TStringList.Create do
    try
     LoadFromFile(FileName);
     Result:=Pos(MyWord, Text)>0;
    finally
      Free;
    end;
end;

Sincerely,
Nestorua.
Avatar of Manuel Lopez-Michelone
If you want speed you can use an hyperstring unit... Try www.torry.ru for many search strings units and components.

best regards,
Manuel Lopez (lopem)
Avatar of Dinkleburger

ASKER

Thank you everyone for excellent help
All the answers are very good but can only be one winner today *smiles* lol
First to the line today was Motaz
Thankyou all
regards Dinkleburger
Thanks Dinkleburger.

Motaz