//这里它在创建流的时候,给流了一个编码 这种转换我查了 官方文档 受益匪浅
{从字符串到十六进制的函数}
function StrToHex(str: string; AEncoding: TEncoding): string;
var
ss: TStringStream;
i: Integer;
begin
Result := '';
ss := TStringStream.Create(str, AEncoding);
for i := 0 to ss.Size - 1 do
Result := Result + Format('%.2x ', [ss.Bytes[i]]);
ss.Free;
end;
the System.Classes.TStringStream class now includes an overloaded constructor that enables the developer to define encoding for strings that will be added to an instance of System.Classes.TStringStream.
所以在创建的时候 就给它编码了:ss := TStringStream.Create(str, AEncoding);
本文来自博客园,作者:del88,转载请注明原文链接:https://www.cnblogs.com/del88/archive/2012/02/29/2374796.html