本文整理自网络,侵删。
//字符串转16进制
function StrToHex(src:string): string;
var
i: integer;
des: string;
begin
des := '';
for i := 1 to Length(src) do
begin
des := des + IntToHex(Ord(src[i]),2) + ' ';
end;
Result := des;
end;
字符串转16进制,其它平台结果相同
//经测试,以下代码任意平台测试结果相同
function StrToHex2(AStr: string): string;
var
Idx: Cardinal;
begin
Result:='';
for Idx := Low(AStr)to High(AStr)do begin
Result:= Result + IntToHex(Ord(AStr[Idx]), 4);
end;
end;
// 调用
procedure TForm1.Button1Click(Sender: TObject);
begin
Showmessage(StrToHex2('你好中国'));
end;
相关阅读 >>
Delphi try abort、exit except 、finally end 执行情况
Delphi中format与formatdatetime函数详解
Delphi idhttp解决获取utf-8网页中文乱码问题
更多相关阅读请进入《Delphi》频道 >>