delphi中如何获得字符串中某字符出现的次数?有这样的函数吗?如果没有该如何去写?请各位大侠执教!

解决方案 »

  1.   

    我刚刚接触delphi,所以对delphi中的函数不是很了解。
      

  2.   

    function CharCount(Const ss:String;Ch:Char):integer;
    var i:integer;
    begin
       ReSult:=0;
       for i:=1 to Length(ss) do
         if ss[i]=Ch then
              inc(ReSult);end;
      

  3.   

    var
      sub, source: String;
      Count : Integer;
    begin
      source := 'asdsdfasdfgerdfrt';
      sub := 'as';
      Count := (Length(source) - Length(StringReplace(source, sub, '',[rfReplaceAll]))) div Length(sub);
      ShowMessage(IntToStr(Count));
    end;
      

  4.   

    多谢了,我刚接触delphi一周,要学的东西还很多。
      

  5.   

    function strCount( subs:String;s:Char):integer;begin
       ReSult:=0;
        while pos(subs,s)<>0 then
          begin
            result:=result+1;
            s:=copy(s,pos(subs,s)+length(subs),1000);      
          end;
    end;