function tform1.StrCount(DStr:string;substr:String):Integer;
var
tstr:string;
i,j:Integer;
begin
i:=0;
j:=Pos(SubStr,Dstr);
tstr:=Dstr;
while (j<>0) do
begin
Inc(i);
tstr:=Copy(tstr,(j+Length(SubStr)),(Length(tstr)-Length(SubStr)));
j:=Pos(SubStr,tstr);
end;
Result :=i;
end;
调用
caption :=inttostr(strcount('123412','12'));