VB URL编码函数

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

相关文章

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

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

VB UTC+8校正 源码

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

vb导出其他文件资源

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

VB改变图片大小的函数

Public Function ResizePicture(ByVal sourceImage As Bitmap, _ ByVal newSize As Si...

VB 调用摄像头拍照,并保存图片...

VB 调用摄像头拍照 1、首先创建一个标准EXE工程 2、在窗体代码中加入如下必需的API及一个拍照的自定义函数 Private...

[VB函数]将资源文件输出到指定目录下

Private Function UnRes(ByVal ResID As Integer, ByVal ResName As String, ByVal UnResPath As String)...

发表评论    

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