javascript urlEncoding和urlDecoding

   < script language = vbs >
function  urldecoding(vstrin)
' qiushuiwuhen(2002-6-19)
     dim  i,strreturn,strSpecial
    strSpecial 
=   " !""#$%&'()*+,/:;<=>?@[]^`{|}~% "
    strreturn 
=   ""
    
for  i  =   1   to   len (vstrin)    
        thischr 
=   mid (vstrin,i, 1 )
        
if  thischr = " % "   then
            intasc
= eval ( " &h " + mid (vstrin,i + 1 , 2 ))
            
if   instr (strSpecial, chr (intasc)) > 0   then
                strreturn
=  strreturn  &   chr (intasc)
                i
= i + 2
            
else
                intasc
= eval ( " &h " + mid (vstrin,i + 1 , 2 ) + mid (vstrin,i + 4 , 2 ))
                strreturn
=  strreturn  &   chr (intasc)
                i
= i + 5
            
end   if
        
else
            
if  thischr = " + "   then
                strreturn
=  strreturn  &   "   "
            
else
                strreturn
=  strreturn  &  thischr
            
end   if
        
end   if
    
next
    urldecoding 
=  strreturn
end function
function  urlencoding(vstrin)
    
dim  i,strreturn,strSpecial
    strSpecial 
=   " !""#$%&'()*+,/:;<=>?@[]^`{|}~% "
    strreturn 
=   ""
    
for  i  =   1   to   len (vstrin)
        thischr 
=   mid (vstrin,i, 1 )
        
if   abs ( asc (thischr))  <   & hff  then
            
if  thischr = "   "   then
                strreturn 
=  strreturn  &   " + "
            
elseif   instr (strSpecial,thischr) > 0   then
                strreturn 
=  strreturn  &   " % "   &   hex ( asc (thischr))
            
else
                strreturn 
=  strreturn  &  thischr
            
end   if
        
else
            innercode 
=   asc (thischr)
            
if  innercode  <   0   then
                innercode 
=  innercode  +   & h10000
            
end   if
            hight8 
=  (innercode   and   & hff00)   & hff
            low8 
=  innercode  and   & hff
            strreturn 
=  strreturn  &   " % "   &   hex (hight8)  &    " % "   &   hex (low8)
        
end   if
    
next
    urlencoding 
=  strreturn
end function
str
= " "
strEncode
= urlencoding(str)
strDecode
= urldecoding(strEncode)
document.write str,
" => " ,strEncode, " => " ,strDecode
</ script >
这是VBS的,大家请注意 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值