procedure TForm1.Button1Click(Sender: TObject); const str = '04 05 06 11'; var I, J: Integer; A: array of Integer; S0, S1: string; begin S0 := str + ' '; S1 := ''; SetLength(A, 0); for I := 1 to Length(S0) do if S0[I] <> ' ' then S1 := S1 + S0[I] else begin SetLength(A, Length(A) + 1); A[High(A)] := StrToIntDef(S1, 0); S1 := ''; end; end;
var A array of string; i,pos:integer; begin pos :=0; str = '04 05 06 11'; for i:=0 to length(str) -1 do begin if str[i] == '' then begin continue; end; A[pos]:=str[i]; pos := pos +1; end; end;
可以用ExtractStrings Delphi有一个ExtractStrings函数。该函数定义为: type TSysCharSet = set of Char; function ExtractStrings(Separators, WhiteSpace: TSysCharSet; Content: PChar; Strings: TStrings): Integer;
procedure TForm1.Button1Click(Sender: TObject);
const
str = '04 05 06 11';
var
I, J: Integer;
A: array of Integer;
S0, S1: string;
begin
S0 := str + ' ';
S1 := '';
SetLength(A, 0); for I := 1 to Length(S0) do
if S0[I] <> ' ' then S1 := S1 + S0[I]
else begin
SetLength(A, Length(A) + 1);
A[High(A)] := StrToIntDef(S1, 0);
S1 := '';
end;
end;
A array of string;
i,pos:integer;
begin
pos :=0;
str = '04 05 06 11';
for i:=0 to length(str) -1 do
begin
if str[i] == '' then
begin
continue;
end;
A[pos]:=str[i];
pos := pos +1;
end;
end;
Delphi有一个ExtractStrings函数。该函数定义为:
type TSysCharSet = set of Char;
function ExtractStrings(Separators, WhiteSpace: TSysCharSet; Content: PChar; Strings: TStrings): Integer;