procedure TForm1.Button1Click(Sender: TObject);
var
str:string;
strlist:TstringList;
begin
str:='1,2,3,4,5,6';
try
strlist:=TstringList.create;
strlist.CommaText:=str;
strlist.Delimiter:=',';
showmessage(inttostr(strlist.Count));
finally
strlist.Free;
end;end;
var
str:string;
strlist:TstringList;
begin
str:='1,2,3,4,5,6';
try
strlist:=TstringList.create;
strlist.CommaText:=str;
strlist.Delimiter:=',';
showmessage(inttostr(strlist.Count));
finally
strlist.Free;
end;end;
a[0]= 字符窜的长度
a[1]= 1
a[2]= ,
a[3]= 2
a[4]= ,
procedure TForm1.Button1Click(Sender: TObject);
var
str:string;
strlist:TstringList;
a:array of string;
i:integer;
begin
str:='1,2,3,4,5,6';
try
strlist:=TstringList.create;
strlist.CommaText:=str;
strlist.Delimiter:=',';
setlength(a,strlist.Count);
for i:=0 to strlist.Count-1 do
begin
a[i]:=strlist.Strings[i];
showmessage(a[i]);
end;
finally
strlist.Free;
end;
end;
顺便谢谢你!!!我先试试!!
procedure TForm1.Button1Click(Sender: TObject);
var
str:string;
strlist:TstringList;
a:array of string;
i:integer;
begin
str:='1,2,3,4,5,6';
str:=stringreplace(str,',',#13+#10,[rfReplaceAll]);
memo1.Text:=str;
try
strlist:=TstringList.create;
strlist.Assign(memo1.Lines);
setlength(a,strlist.Count);
for i:=0 to strlist.Count-1 do
begin
a[i]:=strlist.Strings[i];
showmessage(a[i]);
end;
finally
strlist.Free;
end;
end;
不过这样做有什么必要吗?
j:=0;
for i:= to length(str)
if str[i]=',' then
inc(j)
else
a[j]:=a[j]+str[i];
我用的是delphi6!我帮你看看
procedure TForm1.Button1Click(Sender: TObject);
var
i,index:integer;
ts:Tstringlist;
s:string;
begin
ts:=Tstringlist.create;
s:='1,2,3,4,5,6';
while (pos(',',s)<>0) do
begin
index:=pos(',',s);
ts.add(copy(s,1,index-1));
delete(s,1,index);
end;
ts.add(s);
for i:=0 to ts.count -1do
begin
showmessage(ts.strings[i]);
end;
end;