如何查一个字符串中含有几个'a'????
用什么函数呢?

解决方案 »

  1.   

    { 2002.8.5 Kingron                 }
    { Source:Source string             }
    { Sub:Sub string                   }
    { Return:Count                     }
    { Ex:StrSubCount('abcdbcd','bc')=2 }
    function StrSubCount(const Source, Sub: string): integer;
    var
      Buf               : string;
      i                 : integer;
      Len               : integer;
    begin
      Result := 0;
      Buf:=Source;
      i := Pos(Sub, Buf);
      Len := Length(Sub);
      while i <> 0 do
      begin
        Inc(Result);
        Delete(Buf, 1, i + Len -1);
        i:=Pos(Sub,Buf);
      end;
    end; { StrSubCount }
      

  2.   

    function CountChar(TheStr:String;TheChar:Char):Integer;
      var
        iTmp:Integer;
        iPos:Integer;
      begin
        iTmp:=0;
        for iPos:=Length(TheStr) downto 1 do
          if TheStr[iPos]=TheChar then
            iTmp:=iTmp+1;
        Result:=iTmp;
      end;
      

  3.   

    showmessage( inttostr( CountChar( 'abcadfcab','a' ) ) );