在asp里通过以下两个函数实现javascript里的escape函数和unescape函数功能

时间:2010-03-14 11:30:00 

    在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

  请替换掉中间的双引号

标签:函数,escape,unescape
0
投稿

猜你喜欢

  • golang切片内存应用技巧详解

    2024-05-21 10:19:38
  • PYTHON实现SIGN签名的过程解析

    2021-08-09 13:29:05
  • python opencv实现图像边缘检测

    2022-08-05 08:40:34
  • Python同步遍历多个列表的示例

    2023-08-08 00:20:10
  • Python3解释器知识点总结

    2023-08-02 04:55:38
  • Python人脸识别初探

    2023-01-24 09:39:58
  • 利用二进制文件安装etcd的教程详解

    2023-07-22 00:23:47
  • Oracle存储过程入门学习基本语法

    2009-03-04 11:00:00
  • IntelliJ IDEA连接MySQL数据库详细图解

    2024-01-13 13:18:38
  • 详解java调用ffmpeg转换视频格式为flv

    2024-01-19 03:13:11
  • Windows10下安装解压版MySQL教程图文详解

    2024-01-12 20:40:57
  • 详解Vue.js 可拖放文本框组件的使用

    2024-04-27 15:47:22
  • Python torch.flatten()函数案例详解

    2022-11-11 16:04:27
  • php mysql获取表字段名称和字段信息的三种方法

    2023-11-18 22:47:26
  • 纯JS单页面赛车游戏制作代码分享

    2024-02-23 14:10:17
  • python用match()函数爬数据方法详解

    2023-07-27 12:52:48
  • 机器深度学习二分类电影的情感问题

    2022-07-17 06:13:28
  • Python实现计算圆周率π的值到任意位的方法示例

    2021-09-08 16:47:09
  • Python使用文件操作实现一个XX信息管理系统的示例

    2022-07-12 15:28:31
  • Python利用Pillow(PIL)库实现验证码图片的全过程

    2022-05-18 21:27:47
  • asp之家 网络编程 m.aspxhome.com