Server.URLEncode解码函数

URL编码是指为了将信息通过URL进行传输,所以必须将某些含有特殊意义的字符进行替换的一种编码方式,在asp中我们都知道有一个Server.URLEncode的函数可以完成这个功能。即:

  如果有空格就用%20代替,如果有其它字符就用%ASCII代替,如果有汉字等四个字节的字符,就用两个%ASCII来代替。不过有时候我们也需要将经过这种编码的字符串进行解码,但asp并没有提供相关的函数,这给我们处理问题带来了一定的麻烦。其实我们只要知道了编码规则后,就可以用asp代码来实现我们自己的URlDecode函数了。

function urldecode(encodestr)

 Dim newstr,havechar,lastchar,i,char_c,next_1_c,next_1_Num

 newstr=""

 havechar=false

 lastchar=""

 for i=1 to len(encodestr)

  char_c=mid(encodestr,i,1)

  if char_c="+" then

   newstr=newstr & " "

  elseif char_c="%" then

   next_1_c=mid(encodestr,i+1,2)

   next_1_num=cint("&H" & next_1_c)

   

   if havechar then

    havechar=false

    newstr=newstr & chr(cint("&H" & lastchar & next_1_c))

   else

    if abs(next_1_num)<=127 then

     newstr=newstr & chr(next_1_num)

    else

     havechar=true

     lastchar=next_1_c

    end if

   end if

   i=i+2

  else

   newstr=newstr & char_c

  end if

 next

 urldecode=newstr

end function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值