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 treeview基本用法

Delphi ifdef 另类用法

Delphi url解�a函��(by kingron)

Delphi winapi: isiconic、iszoomed - 分别判断窗口是否已最小化、最大化

Delphi xe 使用asqlite操作sqlite数据库乱码

Delphi case选择语句练习代码简化

Delphi ddk与wdk

Delphi 通用字符串函数

Delphi 泛型数组 strsplit 字符串分割

Delphi listview 设置固定列宽

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



打赏

取消

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

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

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

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

评论

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