function HexToStr(mHex: string): string; var I: Integer; begin Result := ''; for I := 1 to Length(mHex) div 2 do Result := Result + Chr(StrToIntDef('$' + Copy(mHex, I * 2 - 1, 2), 0)); end; { HexToStr }function StrToHex(mStr: string): string; var I: Integer; begin Result := ''; for I := 1 to Length(mStr) do Result := Format('%s%.2x', [Result, Ord(mStr[I])]); end; { StrToHex } procedure TForm1.Button1Click(Sender: TObject); var S: string; begin S := StrToHex('你好'); ShowMessage(S); (*S := StringReplace(S, #32, '', [rfReplaceAll]); //清除空格*) ShowMessage(HexToStr(S)); end;
var
I: Integer;
begin
Result := '';
for I := 1 to Length(mHex) div 2 do
Result := Result + Chr(StrToIntDef('$' + Copy(mHex, I * 2 - 1, 2), 0));
end; { HexToStr }function StrToHex(mStr: string): string;
var
I: Integer;
begin
Result := '';
for I := 1 to Length(mStr) do
Result := Format('%s%.2x', [Result, Ord(mStr[I])]);
end; { StrToHex }
procedure TForm1.Button1Click(Sender: TObject);
var
S: string;
begin
S := StrToHex('你好');
ShowMessage(S);
(*S := StringReplace(S, #32, '', [rfReplaceAll]); //清除空格*)
ShowMessage(HexToStr(S));
end;