本文整理自网络,侵删。
function URLDecode(psSrc: string): string;
{
/// URLDecode modified by Kingron,
/// Support IE6 URL encode: %u3FE5%uA805test
}
var
i: Integer;
ESC: string[2];
CharCode: integer;
WESC: string[4];
begin
result := ''; { do not localize }
psSrc := StringReplace(psSrc, '+', ' ', [rfReplaceAll]); {do not localize}
i := 1;
while i <= Length(psSrc) do
begin
if psSrc[i] <> '%' then { do not localize }
begin {do not localize}
result := result + psSrc[i]
end
else
begin
Inc(i);
if (psSrc[i] = 'u') and (i > 1) and (psSrc[i - 1]= '%') then
begin
Inc(i);
WESC := Copy(psSrc, i, 4);
try
CharCode := StrToInt('$' + WESC);
if (CharCode > 0) and (CharCode < 65536) then
result := result + WideChar(CharCode);
except
end;
Inc(i, 3);
end
else
begin
ESC := Copy(psSrc, i, 2);
Inc(i, 1);
try
CharCode := StrToInt('$' + ESC); {do not localize}
if (CharCode > 0) and (CharCode < 256) then
result := result + Char(CharCode);
except
end;
end;
end;
Inc(i);
end;
end;
相关阅读 >>
Delphi tstreamreader 和tstreamwriter
Delphi windows 编程[20] - 改变菜单项并换行
更多相关阅读请进入《Delphi》频道 >>