function Unescape(const StrEscaped:String):WideString;
function UnescapeUncodeChar(const s:String):WideChar;
var
r:Array [0..1] of Byte;
begin
HexToBin(
PChar(LowerCase(s)),
@r,
SizeOf(r)
);
Result:=WideChar((r[0] shl 8) or r[1]);
end;
function UnescapeAnsiChar(const s:String):Char;
begin
HexToBin(
PChar(LowerCase(s)),
@Result,
SizeOf(Result)
);
end;
var
i:Integer;
c:Integer;
begin
c:=1;
SetLength(Result,Length(StrEscaped));
i:=1;
while i<=Length(StrEscaped) do
begin
if StrEscaped='%' then
begin
if (i<Length(StrEscaped)) and (StrEscaped[i+1]='u') then
begin
Result[c]:=UnescapeUncodeChar(
Copy(
StrEscaped,i+2,4
)
);//Do with '%uxxxx'
Inc(i,6);
end
else
begin
Result[c]:=WideChar(
UnescapeAnsiChar(
Copy(StrEscaped,i+1,2)
)
);//Do with '%xx'
Inc(i,3);
end;
end
else
begin
Result[c]:=WideChar(StrEscaped);
Inc(i);
end;
Inc(c);
end;
SetLength(Result,c-1);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Caption:=Unescape('aA%65%u4E2D%u6587%64Bb');
end;
建议不要使用escape(str),而采用encodeURI(str),如是,
使用HTTPApp单元中HTTPDecode就可以直接进行解码了。