Delphi 中string字符串转换Byte[]字节数组

string字符串转换Byte[]字节数组

procedure TForm1.Button1Click(Sender: TObject);
var
  s:string;
  P:PChar;
  B:array of Byte;
begin
  s:='Hello';
  SetLength(B,Length(S)+1);
  P:=PChar(S);
  CopyMemory(B,p,Length(S)+1);
  Showmessage(Char(B[0]));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
  s:string;
  ab:array of byte;
  i:integer;
begin
  s:='this is a test';
  SetLength(ab,Length(s));
  for i:=1 to length(s) do
    ab[i]:=byte(s[i]);
end;

 b: array[1..7] of byte;

 s: string; 

  

  SetLength(s, 7);

  Move(b[1],s[1], 7 );

完美转换

猜你喜欢

转载自blog.csdn.net/xyzhan/article/details/87269775