VB URL编码函数

小歆12年前软件源码03235
VB UTF-8 URL编码函数:
  1. Public Function UTF8_URLEncoding(szInput)
  2.     Dim wch, uch, szRet
  3.     Dim x
  4.     Dim nAsc, nAsc2, nAsc3
  5.     If szInput = "" Then
  6.         UTF8_URLEncoding = szInput
  7.         Exit Function
  8.     End If
  9.     For x = 1 To Len(szInput)
  10.         wch = Mid(szInput, x, 1)
  11.         nAsc = AscW(wch)
  12.        
  13.         If nAsc < 0 Then nAsc = nAsc + 65536
  14.        
  15.         If (nAsc And &HFF80) = 0 Then
  16.             szRet = szRet & wch
  17.         Else
  18.             If (nAsc And &HF000) = 0 Then
  19.                 uch = "%" & Hex(((nAsc \ 2 ^ 6)) Or &HC0) & Hex(nAsc And &H3F Or &H80)
  20.                 szRet = szRet & uch
  21.             Else
  22.                 uch = "%" & Hex((nAsc \ 2 ^ 12) Or &HE0) & "%" & _
  23.                 Hex((nAsc \ 2 ^ 6) And &H3F Or &H80) & "%" & _
  24.                 Hex(nAsc And &H3F Or &H80)
  25.                 szRet = szRet & uch
  26.             End If
  27.         End If
  28.     Next
  29.     UTF8_URLEncoding = szRet
  30. End Function
VB GB2312 URL编码函数:
  1.    Public Function URLEncode(ByRef strURL)
  2.        Dim I
  3.        Dim tempStr
  4.        For I = 1 To Len(strURL)
  5.            If InStr("-,.0123456789/", Mid(strURL, I, 1)) Then
  6.                URLEncode = URLEncode & Mid(strURL, I, 1)
  7.            Else
  8.                If Asc(Mid(strURL, I, 1)) < 0 Then
  9.                    tempStr = "%" & Right(CStr(Hex(Asc(Mid(strURL, I, 1)))), 2)
  10.                    tempStr = "%" & Left(CStr(Hex(Asc(Mid(strURL, I, 1)))), Len(CStr(Hex(Asc(Mid(strURL, I, 1))))) - 2) & tempStr
  11.                    URLEncode = URLEncode & tempStr
  12.                ElseIf (Asc(Mid(strURL, I, 1)) >= 65 And Asc(Mid(strURL, I, 1)) <= 90) Or (Asc(Mid(strURL, I, 1)) >= 97 And Asc(Mid(strURL, I, 1)) <= 122) Then
  13.                    URLEncode = URLEncode & Mid(strURL, I, 1)
  14.                Else
  15.                    URLEncode = URLEncode & "%" & Hex(Asc(Mid(strURL, I, 1)))
  16.                End If
  17.            End If
  18.        Next
  19.    End Function

相关文章

vb导出其他文件资源

vb导出其他文件资源 Dim TempData() As Byte TempDataPath = "C:\...

VB模拟POST网页上传文件模块【无控件】

VB模拟POST网页上传文件模块【无控件】

介绍 已经集成mod模块,使用的时候直接调用FileUpload函数就可以了。程序是使用抓包软件将上传过程截取下来,通过post模拟上传头数据,再把文件转换为二进制上传到网站上的。...

VB UTC+8校正 源码

Function HttpGet(url) With CreateObject("Msxml2.ServerXMLHTTP") .open "GET", url,...

VB格式输出函数Format的使用

VB格式输出函数可以使数值、日期或字符串按指定的格式输出。其格式为: Format(<表达式>[, <格式字符串>])...

[C语言]用9行代码干掉Windows XP,2000

微软一直声称Windows XP多么多么稳定可靠,但日前一位名为Masaru Tsuchiyama(留在程序下方,所以应该是他的昵称)外国编程爱好者刊出了一小段C语言代码。这一只有9行的小程序如...

从Https跳转到Http时不传递HTTP_REFERER的解决方案

问题场景当http页面通过Referer获取上一个页面的URL时,如果上一个页面是https,则得到的Referer为空。 例如在http页面的PHP代码中使用:$_SERVER['HTTP_REF...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。