本文整理自网络,侵删。
//作者0ak/lyris
function Escape(Str: string): string;
var
I: Integer;
begin
Result := '';
for I := 1 to Length(Str) do
Result := Result + '%' + IntToHex(Ord(Str[I]), 2);
end;
function CharToInt(C: char): Integer;
begin
if ord((C)) >= 65 then
Result := 10 + ord(C) - 65
else
Result := ord(C) - 48;
end;
function HexToInt(Str: string): longint;
var
I: Integer;
p1: array[0..1] of Char;
begIn
Result := 0;
Str := Trim(Str);
for I := 1 to length(Str) do
begIn
StrPcopy(p1, Copy(Str, I, 1));
Result := Result * 16 + CharToInt(p1[0]);
end;
end;
function unescape(Str: string): string;
begin
Result := '';
while Length(Str) >= 3 do
begin
Str[1] := '#';
Result := Result + Chr(HexToInt(Copy(Str, 1, 3)));
Delete(Str, 1, 3);
end;
end;
相关阅读 >>
Delphi使用json解析调用淘宝ip地址库rest api 示例
更多相关阅读请进入《Delphi》频道 >>