delphi能否快速获得一个文本文件中某个字符的数目

解决方案 »

  1.   

    function SubStrConut( //计算子串的个数
      mStr: string; //源字符串
      mSub: string //子串
    ): Integer; //返回子串的个数
    begin
      Result := (Length(mStr) - Length(
        StringReplace(mStr, mSub, '', [rfReplaceAll]))) div Length(mSub);
    end; { SubStrConut }//....
    begin
      with TStringList.Create do try
        LoadFromFile('c:\temp\temp.txt');
        Caption := IntToStr(SubStrConut(Text, 'a'));
      finally
        Free;
      end;
    end;
      

  2.   

    这段代码好像有问题,不能编译通过
    begin
      with TStringList.Create do try
        LoadFromFile('c:\temp\temp.txt');
        Caption := IntToStr(SubStrConut(Text, 'a'));
      finally
        Free;
      end;
    end;
      

  3.   

    -_-!!!!!“//....”不明白是啥?~~难道要这样你才明白?~~unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}function SubStrConut( //计算子串的个数
      mStr: string; //源字符串
      mSub: string //子串
    ): Integer; //返回子串的个数
    begin
      Result := (Length(mStr) - Length(
        StringReplace(mStr, mSub, '', [rfReplaceAll]))) div Length(mSub);
    end; { SubStrConut }procedure TForm1.FormCreate(Sender: TObject);
    begin
      with TStringList.Create do try
        LoadFromFile('c:\temp\temp.txt');
        Caption := IntToStr(SubStrConut(Text, 'a'));
      finally
        Free;
      end;
    end;end.
      

  4.   

    在delphi5开发人员指南得多线程里有一个例子,但偶看不懂。