procedure TForm1.Button1Click(Sender: TObject); var s,st:string; str:TStringList; i:integer; begin s:='40001,40002'; str:=TStringList.Create; try str.CommaText:=s; for i :=0 to str.Count-1 do if st='' then st:=str.Strings[i] else st:=st+str.Strings[i]; showmessage(st); finally str.Free; end; end;
var i,j:Integer; begin i:=40001; j:=40002; showmessage(IntToStr(i)+IntToStr(j)); end;
var i_Arr: Array of Integer; tls: TStringList; I: Integer; begin SetLength(i_Arr, 5); try //初始化测试数据 for I := 1 to 5 do begin i_Arr[I-1] := 40000+I; end; tls := TStringList.Create; try //转换成字符串 for I := 0 to Length(i_Arr) - 1 do begin tls.Add(IntToStr(I)); end; //拼接(注:在Delphi2007之后的版本当中,不需要使用StringReplace,而可以直接设置LineBreak为逗号来实现接接) ShowMessage(StringReplace(tls.Text, #13#10, ',', [rfReplaceAll])); finally tls.Free; end; finally SetLength(i_Arr, 0); i_Arr := Nil; end; end;
我的意思是拼接后的string里是每四个字节的整数,而不是整数字符
var i_Arr: Array of Integer; str: String; I: Integer; P: PChar; begin SetLength(i_Arr, 5); try //初始化测试数据 for I := 1 to 5 do begin i_Arr[I-1] := 40000+I; end; SetLength(str, Length(i_Arr) * sizeof(i_Arr[0])) ; P := PChar(str); //转换成字符串 for I := 0 to Length(i_Arr) - 1 do begin Move(i_Arr[I], P^, sizeof(i_Arr[I])); Inc(P, sizeof(i_Arr[I])); end;
procedure TForm1.Button1Click(Sender: TObject);
var
s,st:string;
str:TStringList;
i:integer;
begin
s:='40001,40002';
str:=TStringList.Create;
try
str.CommaText:=s;
for i :=0 to str.Count-1 do
if st='' then st:=str.Strings[i]
else st:=st+str.Strings[i];
showmessage(st);
finally
str.Free;
end;
end;
i,j:Integer;
begin
i:=40001;
j:=40002;
showmessage(IntToStr(i)+IntToStr(j));
end;
i_Arr: Array of Integer;
tls: TStringList;
I: Integer;
begin
SetLength(i_Arr, 5);
try
//初始化测试数据
for I := 1 to 5 do begin
i_Arr[I-1] := 40000+I;
end; tls := TStringList.Create;
try
//转换成字符串
for I := 0 to Length(i_Arr) - 1 do begin
tls.Add(IntToStr(I));
end;
//拼接(注:在Delphi2007之后的版本当中,不需要使用StringReplace,而可以直接设置LineBreak为逗号来实现接接)
ShowMessage(StringReplace(tls.Text, #13#10, ',', [rfReplaceAll])); finally
tls.Free;
end;
finally
SetLength(i_Arr, 0);
i_Arr := Nil;
end;
end;
var
i_Arr: Array of Integer;
str: String;
I: Integer;
P: PChar;
begin
SetLength(i_Arr, 5);
try
//初始化测试数据
for I := 1 to 5 do begin
i_Arr[I-1] := 40000+I;
end; SetLength(str, Length(i_Arr) * sizeof(i_Arr[0])) ;
P := PChar(str); //转换成字符串
for I := 0 to Length(i_Arr) - 1 do begin
Move(i_Arr[I], P^, sizeof(i_Arr[I]));
Inc(P, sizeof(i_Arr[I]));
end;
finally
SetLength(i_Arr, 0);
i_Arr := Nil;
end;
end;
i_Arr: Array of Integer;
str: String;
I: Integer;
begin
SetLength(i_Arr, 5);
try
//初始化测试数据
for I := 1 to 5 do begin
i_Arr[I-1] := 40000+I;
end; //转换成字符串
SetString(str, PChar(@i_Arr[0]), Length(i_Arr) * sizeof(i_Arr[0]));
finally
SetLength(i_Arr, 0);
i_Arr := Nil;
end;
end;
Str := #$41#$9c#$00#$00#$42#$9c#$00#$00;
吧?