怎样判断在a.txt文件是否存在bbb字符串?

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with TStringList.Create do try
        LoadFromFile('a.txt');
        if Pos('aaa', Text) > 0 then { TODO : 包含"aaa"字符 };
        if IndexOf('aaa') >= 0 then { TODO : 包含"aaa"行 };
      finally
        Free;
      end;
    end;
      

  2.   

    if IndexOf('aaa') >= 0 then 这句怎么会报错?
      

  3.   

    to  foxrun(绿酒金杯) :
    没有错误啊!
      

  4.   

    str := TStringList.Create;
      str.LoadFromFile('c:\1.txt');
      if Pos('aaa', str.Text) > 0 then
            { TODO : 包含"aaa"字符 };
      if str.IndexOf('aaa') >= 0 then
            { TODO : 包含"aaa"行 };我喜欢老老实实的写.....楼上的猩猩忘记写with..do..的begin..end;了
    所以foxrun会出错
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with TStringList.Create do try
        LoadFromFile('a.txt');
        if Pos('aaa', Text) > 0 then { TODO : 包含"aaa"字符 };
        if IndexOf('aaa') >= 0 then { TODO : 包含"aaa"行 };
      finally
        Free;
      end;
    end;
      

  6.   

    强烈建议borland,我觉得这是一个经常遇上的问题,Delphi应该用定义汇编写一个速度很快的函数来实现这个功能!