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 );
完美转换
字符串转字节数组
本文介绍了在Delphi中将字符串(string)转换为字节数组(Byte[])的三种方法。第一种方法使用了PChar和CopyMemory函数,第二种方法通过for循环逐个字符转换,第三种方法利用了Move函数进行快速转换。
4735

被折叠的 条评论
为什么被折叠?



