asp函数实现javascript里的escape函数和unescape函数功能


在asp里通过以下两个函数实现javascript里的escape函数和unescape函数功能。在ajax post或get时内容存在汉字就容易出现乱码,用这两个函数可以得到解决。

Function vbsEscape(str)'加密
     dim i,s,c,a
     s=""
     For i=1 to Len(str)
         c=Mid(str,i,1)
         a=ASCW(c)
         If (a>=48 and a<=57) or (a>=65 and a<=90) or (a>=97 and a<=122) Then
             s = s & c
         ElseIf InStr("@*_+-./",c)>0 Then
             s = s & c
         ElseIf a>0 and a<16 Then
             s = s & "%0" & Hex(a)
         ElseIf a>=16 and a<256 Then
             s = s & "%" & Hex(a)
         Else
             s = s & "%u" & Hex(a)
         End If
     Next
     vbsEscape = s
End Function


Function vbsUnEscape(str)'解密
     dim i,s,c
     s=""
     For i=1 to Len(str)
         c=Mid(str,i,1)
         If Mid(str,i,2)="%u" and i<=Len(str)-5 Then
             If IsNumeric("&H" & Mid(str,i+2,4)) Then
                 s = s & CHRW(CInt("&H" & Mid(str,i+2,4)))
                 i = i+5
             Else
                 s = s & c
             End If
         ElseIf c="%" and i<=Len(str)-2 Then
             If IsNumeric("&H" & Mid(str,i+1,2)) Then
                 s = s & CHRW(CInt("&H" & Mid(str,i+1,2)))
                 i = i+2
             Else
                 s = s & c
             End If
         Else
             s = s & c
         End If
     Next
     vbsUnEscape = s
End Function


[本日志由 随然 于 2008-11-11 05:25 PM 编辑]
上一篇: 国内八家域名注册商优缺点比较
下一篇: 用ASP真正动态实现FLASH幻灯片新闻代码
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: ASP 加密 网页
相关日志:
评论: 0 | 引用: 0 | 查看次数: 10132
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1 字 | UBB代码 关闭 | [img]标签 关闭