有没有具有这样功能的函数?

解决方案 »

  1.   

    没有,要自己写,正好我写过1个,供参考:procedure TForm1.Button1Click(Sender: TObject);
    var
      t:tstringlist;
      s:widestring;
      i,j:integer;
      s1:string;
      p:bool;
    begin
      s:='asgfhj你好你好吗?';
      t:=tstringlist.create;
      for i:=1  to length(s) do
      begin
        s1:=s[i];
        p:=false;
        for j:=0 to t.Count-1 do
        begin
           if s1=t.Names[j] then
           begin
              p:=true;
              break;
           end;
        end;
        if p then
        begin
           t.Values[s1]:=Inttostr(strtoint(t.Values[s1])+1);
        end else
           t.Add(s1+'=1');
      end;
      Memo1.lines:=t;
      t.Free;
    end;
      

  2.   

    Java里我知道有个方法,算是符合你题意吧。你看看行不?
    String str = "1212121";
    System.out.println(str.split("1").length);
    这里面的1就是你要搜索的字符。分割后得到数组的长度就是这个字符出现的次数。感觉还蛮方便的。
      

  3.   

    试试这个
    function Getchnum(Deststr:string;Findch:char):Integer;
    var
       Beginnum,Chnum:Integer;
    begin
       beginnum:=0;
       chunm:=0;
       while Beginnum<=Length(Deststr) do
       begin
         if Deststr[Beginnum]=Findch then
           Inc(Chnum);
         Inc(Beginnum);
       end;
       Result := Chnum;
    end;
      

  4.   


    function GetStrNum(const SubStr, S: string): Integer;
    var
      I: Integer;
    begin
      Result := 0;
      I := PosEx(SubStr, S, 1);
      if I > 0 then
        Inc(Result)
      else
        Exit;  while (I > 0) and (I < Length(S)) do
      begin
        I := PosEx(SubStr, S, I + 1);
        if I > 0 then
          Inc(Result);
      end;
    end;ShwMessage(IntToStr(GetStrNum('12', '12312')));支持子字符串在另外个字符串中出现的次数
      

  5.   

    加上
    uses
      StrUtils;
      

  6.   


    没有,有定位第一次出现的函数pos
      

  7.   

    给你一个函数吧,直接调用即可。
    function SubStrConut(mStr, mSub: string): Integer;   //返回mSub字符串在mStr字符串中的个数
    begin
      Result := (Length(mStr) - Length(StringReplace(mStr,mSub,'',[rfReplaceAll])))
               div Length(mSub); 
    end;
      

  8.   

    for I=0 I<str.length i++
    begin
      if str[i]=c then count++
    end;
    此法比较快如果觉得还慢 那就汇编吧