str :array[1..max] of string;s:='123 4567 891051'i:=1;
str[1]:='';
for j:=1 to length(s) do
begin
if s[j]<>' ' then str[i]:=str[i]+s[j]
else begin inc(i); str[i]:=''; end;
end;
str[1]:='';
for j:=1 to length(s) do
begin
if s[j]<>' ' then str[i]:=str[i]+s[j]
else begin inc(i); str[i]:=''; end;
end;
Des,Sou :string;
P :PChar;
begin
Sou := '12345 645 00';
P := PChar(Sou);
repeat
if P^<>' ' then Des :=Des + P^;
Inc(P);
until P^=#0;
end;
var
s:string;
i,j:integer;
Temp:array of string;
begin
s:='123 4567 891051';
j:=length(s);
setlength(temp,j);
j:=0;
while pos(' ',s)>0 do
begin
i:=pos(' ',s);
Temp[j]:=Copy(s,1,i-1);
j:=j+1;
s:=RightStr(s,length(s)-i);
s:=trim(s);
end;
temp[j]:=s;
for i:=0 to j do
begin
showmessage(temp[i]);
end;
end;
无论你有多少个空格相连都能搞定,结果存在数组temp中
Var
ss : TStrings;
Begin
ss := TStringList.Create;
ss.CommaText := '123 4567 891051';
// ss.Strings[0] is '123', [1] is '4567' ...
ss.Free;
End;虽然CommaText是为','分隔串设计的,但也支持空格。