var
s: string;
sl: TStringList;
begin
s := 'aa,bb,cc,dd,';
sl := TStringList.Create;
while Pos(',', s)>0 do
begin
sl.Add(LeftStr(s, Pos(',', s) - 1));
s := RightStr(s, Length(s) - Pos(',', s));
end;
{ ... }
end;
Function gfDhfg(Astring:string):Tstringlist;
var str1,str2:string;
i:integer;
begin
Result:=TStringList.Create;
i:=pos(',',Astring);
str2:= Astring;
while i>0 do
begin
str1:=copy(str2,1,i-1);
if trim(str1)<>'' then
Result.Add(str1);
str2:=copy(str2,i+1,length(str2)) ;
i:=pos(',',str2);
end;
if (str1<>str2) and (str2<>'') then
Result.Add(str2);
end;
靠,搞那么麻烦干什么,用下面的方法:
var
sl:TStringList;
s:String;
i:integer;
begin
try
sl:=TStringList.create;
s:='a,b,c';
s:=StringReplace(s,',',#13#10,[rfReplaceAll, rfIgnoreCase]);
sl.text:=s;
for i:=0 to sl.count-1 do
begin
//一个一个取出来就好了
end;
finally
sl.free;
end;
end;