VB URL编码函数

小歆12年前软件源码03559
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

相关文章

开启Win7开始菜单右边的快速启动栏

1.在任务栏上点击鼠标右键 -> 工具栏 -> 新建工具栏。 2.在文件夹里输入这个路径,然后按Enter: %userprofile%\AppData\Roaming\Microso...

VB代码优化的六条军规

       在优化程序代码大小的诸多技术中,大多包括从代码中删除不必要的元素。在编译应用程序时,Visual Basic自动删除某些元素。而标识符名称、...

Xcode官方直接下载地址(xip文件)

Xcode官方直接下载地址(xip文件)

获取方法 使用苹果开发者账号访问https://developer.apple.com/downloads/网站,在左侧列表中选择Developer Tools选项,然后在右侧的列表...

vb参考资料.jpg

VB编程语言参考手册

VB编程语言参考手册 资源目录: 小歆网盘:VB编程语言参考手册.rar...

VB中LostFocus、GotFocus事件的改进

---- VB中有一个LostFocus事件和一个GotFocus事件,看名字似乎是当当前窗口失去焦点或得到焦点时触发的事件。但在实际应用时却发现当这个窗口和Win...

VB获取网页源代码的五种方法

方法1:inet控件调用方法 Inet1.OpenURL     添加microsoft ineternet transfor conctrol6.0 控件   &n...

发表评论    

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