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;
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;
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;
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;
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;
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;
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;
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;