VB6 VBA Access真正可用并且完美支持中英文的 URLEncode 與 URLDecode 函數(shù)源碼
- 2021-11-04 11:06:00
- tmtony 原創(chuàng)
- 15645
VB6 Excel VBA Access VBA環(huán)境下:真正可用并且完美支持中英文的 URLEncode 與 URLDecode 2個(gè)函數(shù)源碼
函數(shù)用途:向網(wǎng)頁(yè)Get 或 Post提交數(shù)據(jù)時(shí),經(jīng)常要對(duì)文本Url編碼 Url解碼
網(wǎng)上很多 Url編碼解碼函數(shù)都是有問(wèn)題的。這兩天要處理一個(gè)URL解碼 代碼。找了很多代碼,并修改測(cè)試,測(cè)試后這2個(gè)函數(shù)是成功的。
一個(gè)是解密函數(shù) URLDecode,一個(gè)是加密函數(shù) URLEncode
Function URLDecode(strIn) 'Tmtony親測(cè)成功的 這個(gè)是成功的 支持中文 嘗試多種不同的字符是正確的 URLDecode = "" Dim sl: sl = 1 Dim tl: tl = 1 Dim key: key = "%" Dim kl: kl = Len(key) sl = InStr(sl, strIn, key, 1) Do While sl > 0 If (tl = 1 And sl <> 1) Or tl < sl Then URLDecode = URLDecode & Mid(strIn, tl, sl - tl) End If Dim hh, hi, hl Dim a Select Case UCase(Mid(strIn, sl + kl, 1)) Case "U": 'Unicode URLEncode a = Mid(strIn, sl + kl + 1, 4) URLDecode = URLDecode & ChrW("&H" & a) sl = sl + 6 Case "E": 'UTF-8 URLEncode hh = Mid(strIn, sl + kl, 2) a = Int("&H" & hh) 'ascii碼 If Abs(a) < 128 Then sl = sl + 3 URLDecode = URLDecode & Chr(a) Else hi = Mid(strIn, sl + 3 + kl, 2) hl = Mid(strIn, sl + 6 + kl, 2) a = ("&H" & hh And &HF) * 2 ^ 12 Or ("&H" & hi And &H3F) * 2 ^ 6 Or ("&H" & hl And &H3F) If a < 0 Then a = a + 65536 URLDecode = URLDecode & ChrW(a) sl = sl + 9 End If Case Else: 'Asc URLEncode hh = Mid(strIn, sl + kl, 2) '高位 a = Int("&H" & hh) 'ascii碼 If Abs(a) < 128 Then sl = sl + 3 Else hi = Mid(strIn, sl + 3 + kl, 2) '低位 a = Int("&H" & hh & hi) '非ascii碼 sl = sl + 6 End If URLDecode = URLDecode & Chr(a) End Select tl = sl sl = InStr(sl, strIn, key, 1) Loop URLDecode = URLDecode & Mid(strIn, tl) 'TmTony 測(cè)試過(guò)帶符號(hào) 帶全角 帶中文 帶數(shù)字 帶小寫字母 結(jié)果是對(duì)的 End Function
編碼函數(shù)
Public Function UrlEncode(ByRef szString As String) As String '由我們Office交流網(wǎng)論壇版主roadbeg提供 Dim szChar As String Dim szTemp As String Dim szCode As String Dim szHex As String Dim szBin As String Dim iCount1 As Integer Dim iCount2 As Integer Dim iStrLen1 As Integer Dim iStrLen2 As Integer Dim lResult As Long Dim lAscVal As Long szString = Trim$(szString) iStrLen1 = Len(szString) For iCount1 = 1 To iStrLen1 szChar = Mid$(szString, iCount1, 1) lAscVal = AscW(szChar) If lAscVal >= &H0 And lAscVal <= &HFF Then If (lAscVal >= &H30 And lAscVal <= &H39) Or (lAscVal >= &H41 And lAscVal <= &H5A) Or (lAscVal >= &H61 And lAscVal <= &H7A) Or lAscVal = 61 Or lAscVal = 38 Or lAscVal = 95 Then szCode = szCode & szChar Else szCode = szCode & "%" & Hex(AscW(szChar)) End If Else szHex = Hex(AscW(szChar)) iStrLen2 = Len(szHex) For iCount2 = 1 To iStrLen2 szChar = Mid$(szHex, iCount2, 1) Select Case szChar Case Is = "0" szBin = szBin & "0000" Case Is = "1" szBin = szBin & "0001" Case Is = "2" szBin = szBin & "0010" Case Is = "3" szBin = szBin & "0011" Case Is = "4" szBin = szBin & "0100" Case Is = "5" szBin = szBin & "0101" Case Is = "6" szBin = szBin & "0110" Case Is = "7" szBin = szBin & "0111" Case Is = "8" szBin = szBin & "1000" Case Is = "9" szBin = szBin & "1001" Case Is = "A" szBin = szBin & "1010" Case Is = "B" szBin = szBin & "1011" Case Is = "C" szBin = szBin & "1100" Case Is = "D" szBin = szBin & "1101" Case Is = "E" szBin = szBin & "1110" Case Is = "F" szBin = szBin & "1111" Case Else End Select Next iCount2 szTemp = "1110" & Left$(szBin, 4) & "10" & Mid$(szBin, 5, 6) & "10" & Right$(szBin, 6) For iCount2 = 1 To 24 If Mid$(szTemp, iCount2, 1) = "1" Then lResult = lResult + 1 * 2 ^ (24 - iCount2) Else: lResult = lResult + 0 * 2 ^ (24 - iCount2) End If Next iCount2 szTemp = Hex(lResult) szCode = szCode & "%" & Left$(szTemp, 2) & "%" & Mid$(szTemp, 3, 2) & "%" & Right$(szTemp, 2) End If szBin = vbNullString lResult = 0 Next iCount1 UrlEncode = szCode End Function
分享
Access數(shù)據(jù)庫(kù)自身
- office課程播放地址及課程明細(xì)
- Excel Word PPT Access VBA等Office技巧學(xué)習(xí)平臺(tái)
- 將( .accdb) 文件格式數(shù)據(jù)庫(kù)轉(zhuǎn)換為早期版本(.mdb)的文件格式
- 將早期的數(shù)據(jù)庫(kù)文件格式(.mdb)轉(zhuǎn)換為 (.accdb) 文件格式
- KB5002984:配置 Jet Red Database Engine 數(shù)據(jù)庫(kù)引擎和訪問(wèn)連接引擎以阻止對(duì)遠(yuǎn)程數(shù)據(jù)庫(kù)的訪問(wèn)(remote table)
- Access 365 /Access 2019 數(shù)據(jù)庫(kù)中哪些函數(shù)功能和屬性被沙箱模式阻止(如未啟動(dòng)宏時(shí))
- Access Runtime(運(yùn)行時(shí))最全的下載(2007 2010 2013 2016 2019 Access 365)
Access VBA函數(shù)模塊
- access vba代碼太長(zhǎng),換行,分行的寫法
- VB6 VBA Access真正可用并且完美支持中英文的 URLEncode 與 URLDecode 函數(shù)源碼
- 自定義VB中的urlencode函數(shù),將URL中特殊部分進(jìn)行編碼
- Access 函數(shù)簡(jiǎn)化串接sql字符串,減少符號(hào)導(dǎo)致的書寫錯(cuò)誤
- vba完全關(guān)閉IE瀏覽器及調(diào)用IE瀏覽器的簡(jiǎn)單應(yīng)用
- 利用FollowHyperlink方法打開超鏈接提示“無(wú)法下載您要求的信息”的解決方案
- 在access中用代碼打開文本框中超鏈接地址
Access Activex第三方控件
- Activex控件或Dll 在某些電腦無(wú)法正常注冊(cè)的解決辦法(regsvr32注冊(cè)時(shí)卡?。?/a>
- office使用部分控件時(shí)提示“您沒(méi)有使用該ActiveX控件許可的問(wèn)題”的解決方法
- RTF文件(富文本格式)的一些解析
- Access樹控件(treeview) 64位Office下出現(xiàn)橫向滾動(dòng)條不會(huì)自動(dòng)定位的解決辦法
- Access中國(guó)樹控件 在win10電腦 節(jié)點(diǎn)行間距太小的解決辦法
- EXCEL 2019 64位版(Office 2019 64位)早就支持64位Treeview 樹控件 ListView列表等64位MSCOMMCTL.OCX控件下載
- VBA或VB6調(diào)用WebService(直接Post方式)并解析返回的XML
Access ADP Sql Server等
- 早期PB程序連接Sqlserver出現(xiàn)錯(cuò)誤
- MMC 不能打開文件C:/Program Files/Microsoft SQL Server/80/Tools/Binn/SQL Server Enterprise Manager.MSC 可能是由于文件不存在,不是一個(gè)MMC控制臺(tái),或者用后來(lái)的MMC版
- sql server連接不了的解決辦法
- localhost與127.0.0.1區(qū)別
- Roych的淺談數(shù)據(jù)庫(kù)開發(fā)系列(Sql Server)
- sqlserver 自動(dòng)備份對(duì)備份目錄沒(méi)有存取權(quán)限的解決辦法
- 安裝Sql server 2005 express 和SQLServer2005 Express版企業(yè)管理器 SQLServer2005_SSMSEE
Access 行業(yè)應(yīng)用開發(fā)
文章分類
聯(lián)系我們
聯(lián)系人: | 王先生 |
---|---|
Email: | 18449932@qq.com |
QQ: | 18449932 |
微博: | officecn01 |