我在用的一个比较原始的方法:
function GetStrCount(vSource,vKey:String):Integer;
var
vCount:integer;
vTmpSource:String;
begin
vTmpSource:=vSource;
vCount:=0;
while Pos(vKey,vTmpSource)<>0 do
begin
vTmpSource:=Copy(vTmpSource,Pos(vKey,vTmpSource)+1,Length(vTmpSource));
Inc(vCount);
end;
Result:=vCount;
end;
用循环
j:=0;
while j<ListBox1.Items.Count do
begin
vStr:='';
for i:=0 to 9 do
begin
if j=ListBox1.Items.Count then 不足10个退出
Break;
vStr:=vStr+ListBox1.Items[j];
Inc(j);
end;
ListBox2.Items.Add(vStr);
end;
procedure TForm1.FormShow(Sender: TObject);
var i:integer;
begin
for i:=0 to 35 do
listbox1.Items.Add('a'+inttostr(i));
end;
procedure TForm1.Button1Click(Sender: TObject);
var a:string;
i:integer;
begin
for i:=1 to 30 do
if i mod 10<>0 then
begin
a:=a+listbox1.Items[i];
end
else if i mod 10=0 then
begin
listbox2.Items.Add(a);
a:='';
end;
end;
var
i,j:integer;
str:string;
begin
for i:=1 to (listbox1.Items.Count div 10 )+1 do
begin
str:='';
for j:=(i-1)*10 to (i*10-1) do
begin
if j<listbox1.Items.Count then
str:= str+listbox1.Items[j];
end;
listbox2.Items.Add(str);