【发布时间】:2015-03-05 14:51:33
【问题描述】:
我开发了以下函数来将字符串转换为十六进制值。
function StrToHex(const S: String): String;
const
HexDigits: array[0..15] of Char = '0123456789ABCDEF';
var
I: Integer;
P1: PChar;
P2: PChar;
B: Byte;
begin
SetLength(Result, Length(S) * 2);
P1 := @S[1];
P2 := @Result[1];
for I := 1 to Length(S) do
begin
B := Byte(P1^);
P2^ := HexDigits[B shr 4];
Inc(P2);
P2^ := HexDigits[B and $F];
Inc(P1);
Inc(P2);
end;
end;
现在我想知道是否有更有效的方法来转换字符串?
【问题讨论】:
标签: delphi