核心提示:IE的编码 %后面的就是字符的16进制的字符码 %3A - 3A - 16*3+10 - 58 - chr(58) = ':' %2F - 2F - 16*2+15 - 47 - chr(47) =...
IE的编码 %后面的就是字符的16进制的字符码
%3A -> 3A -> 16*3+10 -> 58 -> chr(58) = ":"
%2F -> 2F -> 16*2+15 -> 47 -> chr(47) = "/"
就是转换过程。
我写了个转换的函数:
function urlDecode(url: string): string;
var i, s, g: Integer;
begin
Result :='';
for i := 1 to Length(url) do
begin
if url[i] = '%' then
begin
s := StrtoInt('$' + url[i + 1]) * 16;
g := StrtoInt('$' + url[i + 2]);
Result := Result + Chr(s + g);
end
else if not (((url[i - 1] = '%') and (url[i + 1] <> '%')) or ((url[i - 2] = '%') and (url[i - 1] <> '%') and (url[i + 1] = '%')) or ((url[i - 2] = '%') and (url[i - 1] <> '%') and (url[i + 1] <> '%'))) then
Result := Result + url[i];
end;
end;