为什么80%的码农都做不了架构师?>>>   

我们知道,ASP的Server对象有个URLEncode方法可以对地址进行编码,但却没有相应的解码函数,下边的这个函数可以实现对URLEncode的解码。
下面的代码是从kesion系统扒下的,确实不错,支持utf8格式。

'================================================
'函数名:URLDecode
'作 用:URL解码
'================================================
Function URLDecode(ByVal urlcode)
Dim start,final,length,char,i,butf8,pass
Dim leftstr,rightstr,finalstr
Dim b0,b1,bx,blength,position,u,utf8
On Error Resume Next b0 = Array(192,224,240,248,252,254)
urlcode = Replace(urlcode,"+"," ")
pass = 0
utf8 = -1 length = Len(urlcode) : start = InStr(urlcode,"%") : final = InStrRev(urlcode,"%")
If start = 0 Or length < 3 Then URLDecode = urlcode : Exit Function
leftstr = Left(urlcode,start - 1) : rightstr = Right(urlcode,length - 2 - final) For i = start To final
char = Mid(urlcode,i,1)
If char = "%" Then
bx = URLDecode_Hex(Mid(urlcode,i + 1,2))
If bx > 31 And bx < 128 Then
i = i + 2
finalstr = finalstr & ChrW(bx)
ElseIf bx > 127 Then
i = i + 2
If utf8 < 0 Then
butf8 = 1 : blength = -1 : b1 = bx
For position = 4 To 0 Step -1
If b1 >= b0(position) And b1 < b0(position + 1) Then
blength = position
Exit For
End If
Next
If blength > -1 Then
For position = 0 To blength
b1 = URLDecode_Hex(Mid(urlcode,i + position * 3 + 2,2))
If b1 < 128 Or b1 > 191 Then butf8 = 0 : Exit For
Next
Else
butf8 = 0
End If
If butf8 = 1 And blength = 0 Then butf8 = -2
If butf8 > -1 And utf8 = -2 Then i = start - 1 : finalstr = "" : pass = 1
utf8 = butf8
End If
If pass = 0 Then
If utf8 = 1 Then
b1 = bx : u = 0 : blength = -1
For position = 4 To 0 Step -1
If b1 >= b0(position) And b1 < b0(position + 1) Then
blength = position
b1 = (b1 xOr b0(position)) * 64 ^ (position + 1)
Exit For
End If
Next
If blength > -1 Then
For position = 0 To blength
bx = URLDecode_Hex(Mid(urlcode,i + 2,2)) : i = i + 3
If bx < 128 Or bx > 191 Then u = 0 : Exit For
u = u + (bx And 63) * 64 ^ (blength - position)
Next
If u > 0 Then finalstr = finalstr & ChrW(b1 + u)
End If
Else
b1 = bx * &h100 : u = 0
bx = URLDecode_Hex(Mid(urlcode,i + 2,2))
If bx > 0 Then
u = b1 + bx
i = i + 3
Else
If Left(urlcode,1) = "%" Then
u = b1 + Asc(Mid(urlcode,i + 3,1))
i = i + 2
Else
u = b1 + Asc(Mid(urlcode,i + 1,1))
i = i + 1
End If
End If
finalstr = finalstr & Chr(u)
End If
Else
pass = 0
End If
End If
Else
finalstr = finalstr & char
End If
Next
URLDecode = leftstr & finalstr & rightstr
End Function Function URLDecode_Hex(ByVal h)
On Error Resume Next
h = "&h" & Trim(h) : URLDecode_Hex = -1
If Len(h) <> 4 Then Exit Function
If isNumeric(h) Then URLDecode_Hex = cInt(h)
End Function

转载于:https://my.oschina.net/dongpo/blog/135271

对URLEncode的解码相关推荐

  1. 在线BASE64加密解密、UrlEncode编码/解码、native/ascii在线转换工具 -toolfk程序员工具网

    本文要推荐的[ToolFk]是一款程序员经常使用的线上免费测试工具箱,ToolFk 特色是专注于程序员日常的开发工具,不用安装任何软件,只要把内容贴上按一个执行按钮,就能获取到想要的内容结果.Tool ...

  2. java linux urlencode_iOS urlEncode编码解码(非过时方法,已解决)

    ios urlEncode解决字符串数据以url的形式传递给web服务器时,字符串中是不允许出现空格和特殊字符的,因此通常需要用到urlEncode技术来对url进行简单的编码,以便更好的传输给服务器 ...

  3. java linux urlencode_Javascript下的urlencode编码解码方法decodeURIComponent()

    关于在ASP(Server.UrlEncode).PHP(urlencode())函数编码结果,或是经过asp.php等动态语言直接写入COOKIES的中文字符,用JS读取的时候,都会碰到一个编码的问 ...

  4. js encodeuricomponent php解码,Javascript下的urlencode编码解码方法附decodeURIComponent

    而本文,就大概说说如何在js中通过系统自带的函数去解决这个问题. 关于在ASP(Server.UrlEncode).PHP(urlencode())函数编码结果,或是经过asp.php等动态语言直接写 ...

  5. Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)

    为了一个gb2312下post中文参数到utf-8页面的程序,随闷的难受,查了一下午资料,大部分是讲Gb2312传到Gb2312页面的UrlEncode,没有提供到Utf-8页面的UrlEncode, ...

  6. asp页面和Asp.net页面传中文参数UrlEncode编码以及接收解码

    在asp中加一个链接,指向asp.net网页,但asp.net的网址是经过HttpUtility.UrlEncode转换和HttpUtility.UrlDecode解码的,而asp的server.ur ...

  7. javascript与C#的编码解码问题

    如果是c#asp.net编码:Server.UrlEncode("xml");解码:Server.UrlDecode("xml");如果是javascript编 ...

  8. 【ASP】简单Url编码和Url解码实例

    描述:在数据传输或读取时,有些敏感数据不宜显示传输,特别涉及机密或财务信息,因此使用编码技术尤为重要. 简单实例: URL编码代码: protected void Button1_Click(obje ...

  9. 命令行实现URL编解码

    命令行实现URL编解码 文章目录 命令行实现URL编解码 1. 实现 2. 原理 2.1 url 的编码规则 2.2 printf 附:参考资料 1. 实现 这里的脚本在 GNU bash, vers ...

最新文章

  1. UICollectionView
  2. win32下进程间通信方式之管道、邮件槽、剪切板、共享内存、消息、套接字、RPC、DDE等
  3. zookeeper可视化工具zkui
  4. 如何在Go中编写防弹代码:不会失败的服务器工作流程
  5. 2021中国新锐品牌发展报告
  6. 邻接矩阵有向图的介绍
  7. ajax文件上传进度条实现
  8. A19:Unity(C#)获取当前运行exe路径的方法
  9. 微信小程序入门ColorUI组件库使用方法
  10. pytorch深度学习框架--gpu和cpu的选择
  11. Windows日志分析(上)
  12. a-table的数据内容特定处换行处理
  13. java实现简单区块链毕业设计
  14. python分析比赛_世界杯:用Python分析热门夺冠球队-(附源代码)
  15. 后一个数 减 前一个数 形成新列表
  16. oracle存储过程语法与使用
  17. 2019中兴面试经验
  18. 布隆过滤器(Bloom Filter)初探
  19. 关于项目 java版本QQ——飞Q (含服务器和客户端)
  20. 小书匠 导出html,推荐:Markdown编辑软件 --- 小书匠

热门文章

  1. 模板建站和开发网站区别_湖南网站建设定制网站和模板建站的区别
  2. mme设备内部错误_防爆电气设备安装的三大误区 你中招了没?
  3. 类oracle数据库pss,Oracle笔记
  4. 神策数据成为 Adjust 在中国首家数据分析合作伙伴
  5. 周五话分析 | 两个指标解读用户千百种离开的姿势(跳出率与退出率)
  6. 在Outlook中修改脱机文件(.ost)的保存位置
  7. 安装Discuz!论坛
  8. AC日记——[SDOI2010]大陆争霸 洛谷 P3690
  9. iOS Cookie相关操作
  10. IEEE R10 2021 Special Call For Proposals Related To CoViD‘19