我正在使用此功能,需要反向功能。它将 HEX (unicode) 字符串转换为 unicode (WideString)。我需要反向函数将其转换回来,即 Widestring 回 HEX(unicode)。
function _ConvertHexToWideString(AHex: AnsiString): WideString;
var wBinaryStream: TMemoryStream;
begin
try
wBinaryStream := TMemoryStream.Create;
try
wBinaryStream.Size := Length(AHex) div 2;
if wBinaryStream.Size > 0 then
HexToBin(PAnsiChar(AHex), wBinaryStream.Memory, wBinaryStream.Size);
except
end;
SetString(Result,
PWideChar(wBinaryStream.Memory),
wBinaryStream.Size div SizeOf(WideChar));
finally
FreeAndNil(wBinaryStream);
end;
end;