delphi中URL的汉字编码


本文整理自网络,侵删。

 show.asp?sort=全部&sortlevel=1&gorq=供&n=5&sitename=全部&img=yes&imgfile=/images/dot_g.gif
诸如这样的形式,在百度查询会转成GB2312的编码,每个汉字对应2个%xx%xx ,但是在google,每个汉字则对应的三个%xx%xx%xx,采用的是unicode编码
在delphi2010中,因为引入unicode的缘故,默认的成了3个%xx,导致我的程序出现问题,找了半天,每一个函数能够实现全URL的自动检测编码,所以自己写了一个,共享给大家:
uses
httpapp;
function urlencode(Aurl: string): string;
var
  i: integer;
  stmp,Tstmp: string;
begin
  result:=Aurl;
  if length(Aurl) > 0 then
  begin
    for i := 1 to length(Aurl) do
    begin
      if Integer(Ord(Aurl[i])) >255 then
        begin
        stmp := copy(Aurl, i, 1);
        Tstmp:=HttpEncode(stmp);
        result:=stringreplace(result,stmp,Tstmp,[]);
        end;
    end;
  end;
end;
 
使用:
URL :=urlencode(URL);
则URL中的汉字自动转为gb2312的%xx的编码。

相关阅读 >>

Delphi fmx jpg 保存数据库 从数据库读取

Delphi 10 seattle plus 新特性――system.json.builders

Delphi idhttp中设置非标准头信息和读写cookie

Delphi 如何知道鼠标点击的statusbar的位置

Delphi mscomm 比较完整的用法例子

Delphi tstreamreader tfile assignfile读取文本文件

怀念一下这些经常不记得的Delphi代码

Delphi windows 编程[12] - 菜单与菜单资源(1-3)

Delphi ado 连接mssql数据库

Delphi 递归获取文件夹大小

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



打赏

取消

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

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

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

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

评论

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