怎么返回某个字符在字符串中出现的位置?
比如我想统计','在'sdfsd,sdfds,sdfdsf,dsfdsf'中出现的次数?
不用自己编程,有现成的么
(delphi)

解决方案 »

  1.   

    a;integer;a:=pos('子字符串','字符串');//返回位置
    例如 a=pos('aa','ddaad') 返回3
      

  2.   

    问:'sdfsd,sdfds,sdfdsf,dsfdsf'你有几个's'呀,
    答:8个
      

  3.   

    to:sunkyling(尉迟冉冉)
    我问的是次数,不是位置to:DWGZ() 
      

  4.   

    function GetCount(Sub,Str: string);
    var index: integer;
        Count: integer;
        Tmp:string;
    begin
       Count:= 0;
       Tmp:= Str;
       while true do
       begin
          index:= Pos(Sub,Tmp);
          if not (index>0) then break else
          begin
             inc(count);
             Tmp:= Copy(Tmp,index+Length(Sub),Length(Tmp));
          end;
       end;
       Reault;= Count;
    end;