function SplitString(const source,ch:string):tstrings;
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;
返回的TListString;
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;
返回的TListString;
const
s = '2173973;3789213791;263;721628';
var
StrList: TStringList;
begin
StrList := TStringList.Create;
try
StrList.Delimiter := ';';
StrList.DelimitedText := s;
// s字符串已经以;为分割符解析出来
Memo1.Lines.Assign(StrList);// 验证
finally
FreeAndNil(StrList);
end;
end;
s:String;
a:array[0..30] of string;
begin
s:='2173973;3789213791;263;721628';
i:=0;
while j>0 do
begin
j:=pos(';',S);
if j>0 then
a[i]:=copy(s,1,j-1)
else
a[i]:=s; s:=copy(s,j+1,length(s)-j);
// memo1.lines.add(a[i]);
i:=i+1;
end;
end;
多谢大家指教
也谢谢webnumen的批评
给分
function SplitString(const source,ch:string):tstrings;
var
temp:string;
i:integer;
begin
result:=Tstringlist.Create;
temp:=source; //注:SOURCE=2173973;3789213791;263;721628......
//注:ch:=';' ;
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;
返回的TListString;
这样才正确。