vb æä¹ææ±å转æ¢ægbkç¼ç åèæ¹æ³å¦ä¸ï¼é¢ç两段VB代ç åå«é对UTF-8ï¼UTF8EncodeURIï¼åGB2312ï¼GBKEncodeURIï¼è¿è¡äºç¼ç ç转æ¢ãPrivate Sub command1_click()Debug.Print (UTF8EncodeURI("æ±å"))Debug.Print (GBKEncodeURI("æ±å"))End SubFunction UTF8EncodeURI(szInput)Dim wch, uch, szRetDim xDim nAsc, nAsc2, nAsc3If szInput = "" ThenUTF8EncodeURI = szInputExit FunctionEnd IfFor x = 1 To Len(szInput)wch = Mid(szInput, x, 1)nAsc = AscW(wch)If nAsc 0 Then nAsc = nAsc + 65536If (nAsc And HFF80) = 0 ThenszRet = szRet wchElseIf (nAsc And HF000) = 0 Thenuch = "%" Hex(((nAsc \ 2 ^ 6)) Or HC0) Hex(nAsc And H3F Or H80)szRet = szRet uchElseuch = "%" Hex((nAsc \ 2 ^ 12) Or HE0) "%" _Hex((nAsc \ 2 ^ 6) And H3F Or H80) "%" _Hex(nAsc And H3F Or H80)szRet = szRet uchEnd IfEnd IfNextUTF8EncodeURI = szRetEnd FunctionFunction GBKEncodeURI(szInput)Dim i As LongDim x() As ByteDim szRet As StringszRet = ""x = StrConv(szInput, vbFromUnicode)For i = LBound(x) To UBound(x)szRet = szRet "%" Hex(x(i))NextGBKEncodeURI = szRetEnd Function
温馨提示:答案为网友推荐,仅供参考