Reading pascal file and searching for a particular word in that file

Reply

Join Date: Aug 2006
Posts: 2
Reputation: winpoorni is an unknown quantity at this point 
Solved Threads: 0
winpoorni winpoorni is offline Offline
Newbie Poster

Reading pascal file and searching for a particular word in that file

 
0
  #1
Aug 10th, 2006
Dear all,

im new to Delphi language.can u pls help me to do this one.
i want to read a particular file and searching for a particular word in that file..
pls assist me to do this one in delphi language

Thanx in advance..
Poornima.R
Last edited by winpoorni; Aug 10th, 2006 at 2:23 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 71
Reputation: Micheus is an unknown quantity at this point 
Solved Threads: 4
Micheus's Avatar
Micheus Micheus is offline Offline
Junior Poster in Training

Re: Reading pascal file and searching for a particular word in that file

 
0
  #2
Aug 14th, 2006
The procedure below must be able to count a particular word(SearchStr) occurence in a file(FileName).
Pascal and Delphi Syntax (Toggle Plain Text)
  1. procedure SearchingInFile(Filename, SearchStr :string);
  2. var
  3. SearchPos,
  4. FoundCount :integer;
  5. FileLine :string;
  6. SearchFile :Text;
  7. begin
  8. Assign(SearchFile, Filename);
  9. Reset(SearchFile);
  10. FoundCount := 0;
  11. while not EOF(SearchFile) do
  12. begin
  13. // the search will be no case sensitive (using UpCase)
  14. FileLine := UpCase(Readln(SearchFile));
  15. SearchPos := Pos(UpCase(SearchStr), FileLine);
  16. if SearchPos > 0 then
  17. begin
  18. // looking for more SearchStr into FileLine
  19. while SearchPos > 0 do
  20. begin
  21. // add 1 to founded word count
  22. Inc(FoundCount);
  23. // Advance SearchPos
  24. SearchPos := SearchPos +Length(SearchStr).
  25. // remove substring before last word founded, including the word
  26. FileLine := Copy(FileLine, SearchPos, Length(FileLine));
  27. // check for a new occurence of searched word on line readed
  28. SearchPos := Pos(UpCase(SearchStr), FileLine);
  29. end;
  30. end;
  31. end;
  32. Close(SearchFile);
  33. end;
Is it? :rolleyes:
p.s.: I'm not sure about UpCase function in pascal (today, I'm Delphi programmer), but I think that have some thing similar.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC