版权声明: 本文由Oak/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;
功能不用赘述,JavaScript escape/unescape编码的Delphi实现:)