- 注册时间
- 2011-3-6
- 最后登录
- 1970-1-1
该用户从未签到
|
发表于 2012-4-27 10:10:23
|
显示全部楼层
- Function Utf8ToUnicode(ByRef Utf() As Byte) As String
- Dim lRet As Long
- Dim lLength As Long
- Dim lBufferSize As Long
- lLength = UBound(Utf) - LBound(Utf) + 1
- If lLength <= 0 Then Exit Function
- lBufferSize = lLength * 2
- Utf8ToUnicode = String$(lBufferSize, Chr(0))
- lRet = MultiByteToWideChar(CP_UTF8, 0, VarPtr(Utf(LBound(Utf))), lLength, StrPtr(Utf8ToUnicode), lBufferSize)
- If lRet <> 0 Then
- Utf8ToUnicode = Left(Utf8ToUnicode, lRet)
- End If
- End Function
- Function UnicodeToUtf8(ByVal UCS As String) As Byte()
- Dim lLength As Long
- Dim lBufferSize As Long
- Dim lResult As Long
- Dim abUTF8() As Byte
- lLength = Len(UCS)
- If lLength = 0 Then Exit Function
- lBufferSize = lLength * 3 + 1
- ReDim abUTF8(lBufferSize - 1)
- lResult = WideCharToMultiByte(CP_UTF8, 0, StrPtr(UCS), lLength, abUTF8(0), lBufferSize, vbNullString, 0)
- If lResult <> 0 Then
- lResult = lResult - 1
- ReDim Preserve abUTF8(lResult)
- UnicodeToUtf8 = abUTF8
- End If
- End Function
复制代码 |
|