如何统计字符串中某个字符的数量。
比如:1.2.3.4中“.”的数量,望详细,谢谢!!!!

解决方案 »

  1.   

    procedure dotcount(str:string);
    var i,j:integer;
        istr:string;
    begin
    j:=0;
     for i:=0 to length(str)-1 do 
       begin
         istr:=copy(str,1,1);
         if istr='.';
         j:=j+1;
         delete(str,1,1);
       end;
      showmessage(inttostr(j));
    end;
      

  2.   

    function StrSubCount(const Source, Sub: string): integer;varBuf : string;i : integer;Len : integer;beginResult := 0;Buf:=Source;i := Pos(Sub, Buf);Len := Length(Sub);while i <> 0 dobeginInc(Result);Delete(Buf, 1, i + Len -1);i:=Pos(Sub,Buf);end;end; { StrSubCount }
      

  3.   

    for i:=1 to length(你的字符串) do
      begin
        if copy(字符串,i,1)='.' then
           j:=j+1;
      end
    最后j就是你要的
      

  4.   

    for i:=1 to length(你的字符串) do
      begin
        if copy(字符串,i,1)='.' then
           j:=j+1;
      end
    ==============
    就是这样拉