[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[ASP]共享个我写的URL编码的解码函数--URLDecode

上一篇:[ASP]注意使用ByVal
下一篇:[ASP]ASP实现GB2312字符与区位码的相互转换

添加日期:2007/5/8 15:42:39 快速返回   返回列表 阅读4116次
注释就不写啦,嘿嘿。

对了,这个方法在UTF-8编码时是用不了的……

因为……UTF-8其实就是Unicode啦,它不算某种编码……CHR函数是用不了的……

UTF-8编码的,应该专门写一个,关键在于UTF-8转Unicode……

<%
function urldecode(str) 
    dim newstr,iIndex,sChar,sHexStr,iHex
    newstr="" 
    iIndex=1
    while (iIndex < len(str))
        sChar=mid(str,iIndex,1) 
        if sChar="+" then 
            newstr = newstr & chr(32) 
            iIndex=iIndex +1
        elseif sChar="%" then 
            sChar=mid(str,iIndex+1,1) 
            if sChar="u" then
                sHexStr=mid(str,iIndex+2,4) 
                iHex=cint("&H" & sHexStr)
                newstr = newstr & chrw(iHex) 
                iIndex=iIndex +6
            else
                sHexStr=mid(str,iIndex+1,2)  
                iHex=cint("&H" & sHexStr) 
                if abs(iHex)<=127 then 
                    newstr = newstr & chr(iHex) 
                    iIndex=iIndex+3
                else 
                    sChar=mid(str,iIndex+3,1)
                    if sChar="%" then 
                        sHexStr=sHexStr & mid(str,iIndex+4,2) 
                        iHex=cint("&H" &sHexStr)
                        newstr = newstr & chr(iHex) 
                        iIndex=iIndex+6
                    else 
                        sHexStr=sHexStr & Hex(Asc(sChar))
                        iHex=cint("&H" &sHexStr)
                        newstr = newstr & chr(iHex)
                        iIndex=iIndex+4
                    end if
                end if
            end if
        else
            
            newstr = newstr & sChar
            iIndex=iIndex +1
        end if
    wend
    urldecode=newstr 
end function 
%>
 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved