本文整理自网络,侵删。
Function HexToStr(S: String): String;Var Stream: TMemoryStream; Value: TStringStream; Pos: Integer;Begin Result := ''; If Length(S) > 0 Then Begin Stream := TMemoryStream.Create; Value := TStringStream.Create(''); Try Pos := Stream.Position; Stream.SetSize(Stream.Size + Length(S) Div 2); HexToBin(PChar(S), PChar(Integer(Stream.Memory) + Stream.Position), Length(S) Div 2); Stream.Position := Pos; Value.CopyFrom(Stream, Length(S) Div 2); Result := Value.DataString; Finally Stream.Free; Value.Free; End; End;End;
Function StrToHex(S: String): String;Var Stream: TMemoryStream; Value: TStringStream;Begin If Length(S) > 0 Then Begin Value := TStringStream.Create(S); Try SetLength(Result, (Value.Size - Value.Position) * 2); If Length(Result) > 0 Then Begin Stream := TMemoryStream.Create; Try Stream.CopyFrom(Value, Value.Size - Value.Position); Stream.Position := 0; BinToHex(PChar(Integer(Stream.Memory) + Stream.Position), PChar(Result), Stream.Size - Stream.Position); Finally Stream.Free; End; End; Finally Value.Free; End; End;End;
来源:https://bbs.csdn.net/topics/390876064
相关阅读 >>
Delphi xe5、6、7在android或者ios上使用ansistring和ansichar
Delphi xe 跨平台(windows、android安卓、苹果macos、苹果ios)写法
更多相关阅读请进入《Delphi》频道 >>