//这里它在创建流的时候,给流了一个编码 这种转换我查了 官方文档 受益匪浅
{从字符串到十六进制的函数}
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);

posted on 2012-02-29 23:13  del88  阅读(9)  评论(0编辑  收藏  举报