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中判断某个文件是否已经打开

Delphi 枚举resource资源名

Delphi中如何提高listview删除item的速度

Delphi tstreamreader 和tstreamwriter

Delphi 生成日志记录单元

Delphi判断某个程序是否已经启动

Delphi开发平台 raw socket

Delphi 连接dbf数据

Delphi windows 编程[20] - 改变菜单项并换行

Delphi用ado操作数据库完整示例

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



打赏

取消

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

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

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

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

评论

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