procedure TForm1.Button1Click(Sender: TObject); var i:integer; arr:array of string; str:string; begin str:='12345678'; for i= 1 to length(str) step 2 do begin arr(i/2):=copy(str,i,2); end; end;具体我没有测试,大概就是这个思路,主要就是定义循环,我的思路就是这样的,你可以试一下.
多谢 woshihaoge(支离破碎) 但在运行时提示:for i= 1 to length(str) step 2 do 错误 不知如何解决?
procedure TForm1.Button1Click(Sender: TObject); var i:integer; arr:array of string; str:string; begin str:='12345678'; for i= 1 to length(str) do begin arr(i/2):=copy(str,i,2); i :=i+2; end; end;
我只是给你说了个算法,我手头也没有DELPHI,大概就是这个意思,我给你写的估计语法上的问题,还有,我的循环中要加个i:=i+2 procedure TForm1.Button1Click(Sender: TObject); var i:integer; arr:array of string; str:string; begin str:='12345678'; for i= 0 to length(str) do begin arr(i/2):=copy(str,i,2); i :=i+2; end; end;
可以用substring(……); 具体用法看帮助
var s:string; i:integer; dnyarr:array of byte; begin s:='12334534252345'; if length(s) mod 2= 0 then setlength(dnyarr,length(s) div 2) else setlength(dnyarr,(length(s) div 2)+1); i:=0; while s<>'' do begin dnyarr[i]:=strtoint(copy(s,1,2)); inc(i); s:=copy(s,3,length(s)-2); end;
var
i:integer;
arr:array of string;
str:string;
begin
str:='12345678';
for i= 1 to length(str) step 2 do
begin
arr(i/2):=copy(str,i,2);
end;
end;具体我没有测试,大概就是这个思路,主要就是定义循环,我的思路就是这样的,你可以试一下.
但在运行时提示:for i= 1 to length(str) step 2 do 错误
不知如何解决?
var
i:integer;
arr:array of string;
str:string;
begin
str:='12345678';
for i= 1 to length(str) do
begin
arr(i/2):=copy(str,i,2);
i :=i+2;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
arr:array of string;
str:string;
begin
str:='12345678';
for i= 0 to length(str) do
begin
arr(i/2):=copy(str,i,2);
i :=i+2;
end;
end;
具体用法看帮助
s:string;
i:integer;
dnyarr:array of byte;
begin
s:='12334534252345';
if length(s) mod 2= 0 then
setlength(dnyarr,length(s) div 2)
else
setlength(dnyarr,(length(s) div 2)+1);
i:=0;
while s<>'' do
begin
dnyarr[i]:=strtoint(copy(s,1,2));
inc(i);
s:=copy(s,3,length(s)-2);
end;