循环取吧,用copy,pos等函数。

解决方案 »

  1.   

    Function CharTimes(sChar:String;sStr:String):Integer;
    var iLen,iPos:Integer;
        str: String;
    begin
      iLen := Length(sChar);
      str := sStr;
      Result := 0;
      iPos := POS('sChar',str);
      while iPos > 0 do
      begin
        Result := Result + 1;
        str := Copy(str,iPos+iLen-1,Length(str));
        iPos(POS('sChar',str);)
      end;
    end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
            i,icount:integer;
            s,stosearch:string;
    begin
            s:='AAbbbbbbkkkkAsdfsdfdfAsdfsdAAdd';
            stosearch:='A';        icount:=0;
            for i:=1 to length(s) do
            begin
                    if copy(s,i,length(stosearch))=stosearch then
                        icount:=icount+1;
            end;        showmessage(inttostr(icount));   //
    end;
      

  3.   

    测试:上面的 stosearch='A'时 ,icount=6上面的 stosearch='AA'时 ,icount=2
      

  4.   

    var
        substr, str, copystr: string;
    begin
      str := 'wedfwehqwefdaswe';
      substr := 'we';
      copystr := str;
      while pos(substr, copystr) <> 0 do
      begin
        copystr := copy(copystr, pos(substr, copystr) + length(substr), length(copystr) - pos(substr, copystr) + 1);
        i := i + 1;
      end;
      label1.Caption := inttostr(i);
    end;
      

  5.   

    Function CharTimes(sChar:String;sStr:String):Integer;
    var iLen,iPos:Integer;
    begin
      iLen := Length(sStr);
      Result := 0;
      for iPos=0 to iLen-1 do
        if sChar=sStr[i] then
          inc(Result);
    end;