Delphi中如何打开一个文件,在里面查找指定的字符串?

解决方案 »

  1.   

    文本文件吗?
    用Pos就可以了!
      

  2.   

    assfile(f,'a.txt');
    reset(f);
    while not eof(f) do
    begin
      Readln(F,S);
      if Pos('yourfindstring',S)> 0 then
       begin
         showmessage('找到了');
         break;
       end; 
    end;
    closefile(f);
      

  3.   

    这句:while not eof(f) do  是什么意思啊??
      

  4.   

    var 
      F: TextFile;
      S: string;
    begin
      if OpenDialog1.Execute then    //如果选择文件名成功
      begin
        AssignFile(F, OpenDialog1.FileName); 
        Reset(F);
        While not Eof(F) do          //文件未到末尾
        begin
          Readln(F, S);              //读一行
          if Pos('yourfindstring',S)> 0 then
          begin
            ShowMessage('找到了');
            break;
          end;
        end; 
        CloseFile(F);
      end;
    end;
    -------------------------------
    我的更详细版本
      

  5.   

    文件操作不熟啊,找资料看看吧
    用memo来操作也可以
    memo.lines.LoadFromFile('文件名')
    再用pos查找
      

  6.   

    装载到StringList中更简单.
    var
      str :Tstrings;
      i:integer;
    begin
      str :=TStringList.create;
      str.LoadFromFile('文件全路径');
      for i:=0 to str.count-1 do 
      begin
        if  pos('yourstring',str.string[i])>0 then
           ShowMessage('找到了');
      end;