首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

有关 TEncoding

2012-03-09 
有关 TEncoding 求助这段代码是用在Delphi 2009以上的:function TMainForm.ToHexString(s: string encode

有关 TEncoding 求助
这段代码是用在Delphi 2009以上的:

function TMainForm.ToHexString(s: string; encode: TEncoding): string;
var TmpStr: string;
  ByteAy: Tbytes;
  tmpByte: Byte;
begin
  ByteAy := encode.GetBytes(s);
  TmpStr := '';
  for tmpByte in ByteAy do
  TmpStr := Format('%s%.2x', [tmpstr, tmpbyte]);
  Result := TmpStr;
end;

如何修改使之可以用在delphi7中?或者要用到什么三方控件?高分求助!

[解决办法]
试一试:
http://www.2ccc.com/article.asp?articleid=5090
[解决办法]
看代码是把string转成16进制的文本,可以使用BinToHex函数,代码是:

Delphi(Pascal) code
  Len := Length(s);  SetLength(Result, Len shl 1);  BinToHex(s, PChar(Result), Len);
[解决办法]
Delphi(Pascal) code
function StringToHex(S: String): String;var I: Integer;begin  Result:= '';  for I := 1 to length (S) do    Result:= Result+IntToHex(ord(S[i]),2);end;function HexToString(H: String): String;var I: Integer;begin  Result:= '';  for I := 1 to length (H) div 2 do    Result:= Result+Char(StrToInt('$'+Copy(H,(I-1)*2+1,2)));end; 

热点排行