| | |
Reading pascal file and searching for a particular word in that file
![]() |
The procedure below must be able to count a particular word(SearchStr) occurence in a file(FileName).
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.
Pascal and Delphi Syntax (Toggle Plain Text)
procedure SearchingInFile(Filename, SearchStr :string); var SearchPos, FoundCount :integer; FileLine :string; SearchFile :Text; begin Assign(SearchFile, Filename); Reset(SearchFile); FoundCount := 0; while not EOF(SearchFile) do begin // the search will be no case sensitive (using UpCase) FileLine := UpCase(Readln(SearchFile)); SearchPos := Pos(UpCase(SearchStr), FileLine); if SearchPos > 0 then begin // looking for more SearchStr into FileLine while SearchPos > 0 do begin // add 1 to founded word count Inc(FoundCount); // Advance SearchPos SearchPos := SearchPos +Length(SearchStr). // remove substring before last word founded, including the word FileLine := Copy(FileLine, SearchPos, Length(FileLine)); // check for a new occurence of searched word on line readed SearchPos := Pos(UpCase(SearchStr), FileLine); end; end; end; Close(SearchFile); end;
p.s.: I'm not sure about UpCase function in pascal (today, I'm Delphi programmer), but I think that have some thing similar.
![]() |
Similar Threads
- RE: reading .wav file and putting ito inot the array (C)
- Reading .dat file (Visual Basic 4 / 5 / 6)
- Reading in a text file string is not complete (Pascal and Delphi)
- Reading an input file as a class memeber function (C++)
- reading txt file into array (C++)
- Not reading in entire file. (C++)
- reading and printing a file to screen in C (C)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: dates
- Next Thread: Program for Grep search
| Thread Tools | Search this Thread |





