home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / findrepl.swg / 0008_FINDTEXT.PAS.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-05-28  |  1.3 KB  |  54 lines

  1. {
  2. > I need help on making a Search Procedure in TURBO PASCAL.
  3. > what I want it to do is to open the contents in a Text File
  4. > search For a given String. and diplay that Record or line With that
  5. > given String!!!
  6.  
  7. Here is a Program that will search a Text File and display the lines
  8. of Text With the search String in it.
  9. }
  10.  
  11. Program Search;
  12. Type
  13.   BigString = String[132];
  14. Var
  15.   FileName: String[14];
  16.   FileVar: Text;
  17.   LineNumber: Integer;
  18.   OneLine, Temporary, SubString: BigString;
  19.  
  20. { Make all Chars in S upper case}
  21. Procedure UpperCase(Var S: BigString);
  22. Var
  23.   I: Integer;
  24. begin
  25.   For I := 1 to Length(S) do
  26.     S[I] := Upcase(S[I]);
  27. end;
  28.  
  29. begin
  30.   Write('Search what Text File? ');
  31.   Readln(FileName);
  32.   Assign(FileVar, FileName);
  33.   Repeat
  34.     Writeln;
  35.     Reset(FileVar);
  36.     Write('Search for? (Enter to quit) ');
  37.     Readln(SubString);
  38.     if Length(SubString) > 0 then
  39.     begin
  40.       UpperCase(SubString);
  41.       LineNumber := 0;
  42.       While not Eof(FileVar) do
  43.       begin
  44.         Readln(FileVar, OneLine);
  45.         Inc(LineNumber);
  46.         Temporary := OneLine;
  47.         UpperCase(Temporary);
  48.         if Pos(SubString, Temporary) >0
  49.           Then Writeln(LineNumber:3, ': ', OneLine)
  50.       end
  51.     end
  52.   Until Length(SubString) = 0
  53. end.
  54.