---------------------------------------------------------------
function SplitString(const source,ch:string):TStringlist;
var
temp:string;
i:integer;
begin
result:=tstringlist.Create;
temp:=source;
i:=pos(ch,source);
while i<>0 do
begin
result.Add(copy(temp,0,i-1));
delete(temp,1,i);
i:=pos(ch,temp);
end;
result.Add(temp);
end;
调用:
s:=splitstring('afsdfsdaaa|bbfdsfsdb|ccc','|');
for i:=0 to s.Count-1 do
b:=b+s.Strings+#13;
showmessage(b);
s.free;
---------------------------------------------------------------
var
s,s1:string;
i,i1:integer;
j:integer;
begin
j:=4;
//所需位置
i1:=1;
s:='10,15,12,13';
while i1<4 do
begin
i:=pos(',',s);
i1:=i1+1;
s:=copy(s,i+1,length(s)-i+1);
end;
s1:=copy(s,1,i-1);
edit1.text:=s1;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
s:string;
ss:TStringList;
i:integer;
begin
s:='10,15,12,13';
ss:=TStringList.create;
ss.CommaText:=s;
showmessage(Format('共有%d个数',[ss.count]));
for i:=1 to ss.count do
showmessage(Format('第%d个数为“%s”',[i,ss[i-1]]));
ss.free;
end;