delphi URL解�a函��(By Kingron)


本文整理自网络,侵删。

  
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 httpclient async异步获取网页代码

Delphi firedac 获取 insert 记录的自增 id

Delphi 的运算符列表

Delphi 解决idhttp下载数据时程序无响应的问题

Delphi of 打坐与普通攻击calll调用

Delphi tfontdialog

Delphi stringgrid如何清空

Delphi运行时拖拉、改变元件大小

Delphi clipboard 截图后将图片数据复制到剪贴板

indy 中idhttp元件出现http status 302错误

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    正在狠努力加载,请稍候...