Private Function GetUTF8Code(ByVal sUnicode As String, Optional ByVal fUTFCode As Boolean = False) As Variant Dim i As Long Dim lLength As Long Dim lBufferSize As Long Dim lResult As Long Dim bUTF8() As Byte
GetUTF8Code = "" lLength = Len(sUnicode) If lLength = 0 Then Exit Function lBufferSize = lLength * 3 + 1 ReDim bUTF8(lBufferSize - 1)
If lResult <> 0 Then lResult = lResult - 1 ReDim Preserve bUTF8(lResult) If fUTFCode Then For i = LBound(bUTF8) To UBound(bUTF8) GetUTF8Code = GetUTF8Code & Hex(bUTF8(i)) Next Else GetUTF8Code = bUTF8 End If End If End FunctionPublic Function UTF8_Decode(bUTF8() As Byte) As String Dim lRet As Long Dim lLen As Long Dim lBufferSize As Long Dim sBuffer As String Dim bBuffer() As Byte
Dim i As Long
Dim lLength As Long
Dim lBufferSize As Long
Dim lResult As Long
Dim bUTF8() As Byte
GetUTF8Code = ""
lLength = Len(sUnicode)
If lLength = 0 Then Exit Function
lBufferSize = lLength * 3 + 1
ReDim bUTF8(lBufferSize - 1)
lResult = WideCharToMultiByte(CP_UTF8, 0, StrPtr(sUnicode), lLength, bUTF8(0), lBufferSize, vbNullString, 0)
If lResult <> 0 Then
lResult = lResult - 1
ReDim Preserve bUTF8(lResult)
If fUTFCode Then
For i = LBound(bUTF8) To UBound(bUTF8)
GetUTF8Code = GetUTF8Code & Hex(bUTF8(i))
Next
Else
GetUTF8Code = bUTF8
End If
End If
End FunctionPublic Function UTF8_Decode(bUTF8() As Byte) As String
Dim lRet As Long
Dim lLen As Long
Dim lBufferSize As Long
Dim sBuffer As String
Dim bBuffer() As Byte
lLen = UBound(bUTF8) + 1
If lLen = 0 Then Exit Function
lBufferSize = lLen * 2
sBuffer = String$(lBufferSize, Chr(0))
lRet = MultiByteToWideChar(CP_UTF8, 0, VarPtr(bUTF8(0)), lLen, StrPtr(sBuffer), lBufferSize)
If lRet <> 0 Then
sBuffer = Left(sBuffer, lRet)
End If
UTF8_Decode = sBuffer
End Function
UTF8_Decode是utf8转换回来的
那个网站的文章地址:http://dev.9983.com/ku/5101/4877990.asp