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

来源:asp之家 时间:2009-02-04 15:47:00 

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

类似javascript里的escape函数:

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

类似javascript里的Unescape函数:

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
标签:unescape,escape,函数,加密
0
投稿

猜你喜欢

  • 如何用Cookie进行登录验证?

    2010-06-12 12:34:00
  • Oracle SQL性能优化系列学习二

    2010-07-23 13:23:00
  • 别开生面:纯CSS实现相册滑动浏览

    2008-06-26 13:24:00
  • 如何提高ASP的效率?

    2010-06-07 20:52:00
  • 教程javascript的function(函数)

    2007-09-30 13:38:00
  • ORACLE 正则解决初使化数据格式不一致

    2009-05-24 19:44:00
  • CSS样式表中SPAN和DIV的区别

    2007-10-21 08:47:00
  • asp和php页面全面封杀WVS扫描器的代码

    2011-02-28 10:43:00
  • 擦亮自己的眼睛去看SQL Server之历史渊源

    2011-08-29 15:40:53
  • 网页设计详细教程之XML简便省力技巧五则

    2008-05-23 14:37:00
  • 编写兼容IE和FireFox的脚本

    2009-05-19 12:01:00
  • Oracle数据库索引的维护

    2010-07-26 13:29:00
  • 巧用Dreamweaver MX控制页面元素

    2009-09-13 18:38:00
  • 用ASP对网页进行限制性的访问

    2008-07-03 13:02:00
  • asp datediff 时间相减

    2011-03-25 10:34:00
  • asp中把数据表映射成ajax可调用的json格式的方法

    2010-01-22 15:27:00
  • 网站设计配色方案教程

    2007-10-10 19:38:00
  • 使用Microsoft SQL Server 2000全文搜索功能构建Web搜索应用程序

    2008-09-29 12:32:00
  • 一空间多域名绑定不同目录方法

    2009-03-09 18:32:00
  • SQL Server 2005数据转换服务设计问题集锦

    2008-12-26 17:29:00
  • asp之家 网络编程 m.aspxhome.com