2个回答
展开全部
VB中UTF8转Unicode编码,没见过转中文的,只有中文转UTF-8的!
代码仅供参考:
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long Private Const CP_UTF8 = 65001 'Purpose:Convert Utf8 to Unicode Public Function UTF8_Decode(ByVal sUTF8 As String) As String Dim lngUtf8Size As Long Dim strBuffer As String Dim lngBufferSize As Long Dim lngResult As Long Dim bytUtf8() As Byte Dim n As Long If LenB(sUTF8) = 0 Then Exit Function On Error GoTo EndFunction bytUtf8 = StrConv(sUTF8, vbFromUnicode) lngUtf8Size = UBound(bytUtf8) + 1 On Error GoTo 0 lngBufferSize = lngUtf8Size * 2 strBuffer = String$(lngBufferSize, vbNullChar) 'Translate using code page 65001(UTF-8) lngResult = MultiByteToWideChar(CP_UTF8, 0, bytUtf8(0), _ lngUtf8Size, StrPtr(strBuffer), lngBufferSize) 'Trim result to actual length If lngResult Then UTF8_Decode = Left$(strBuffer, lngResult) End If End Function
把你上面获取的内容转一下就行,比如Text1.Text=UTF8_Decode(strResponse)
还可以加多一句InStr(1, strResponse, "charset=utf-8") > 0判断是否是UTF8编码再执行,不是UTF8的就直接显示。 还有些网页编码那里是大写的,要这样写InStr(1, strResponse, "charset=UTF-8") > 0
代码仅供参考:
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long Private Const CP_UTF8 = 65001 'Purpose:Convert Utf8 to Unicode Public Function UTF8_Decode(ByVal sUTF8 As String) As String Dim lngUtf8Size As Long Dim strBuffer As String Dim lngBufferSize As Long Dim lngResult As Long Dim bytUtf8() As Byte Dim n As Long If LenB(sUTF8) = 0 Then Exit Function On Error GoTo EndFunction bytUtf8 = StrConv(sUTF8, vbFromUnicode) lngUtf8Size = UBound(bytUtf8) + 1 On Error GoTo 0 lngBufferSize = lngUtf8Size * 2 strBuffer = String$(lngBufferSize, vbNullChar) 'Translate using code page 65001(UTF-8) lngResult = MultiByteToWideChar(CP_UTF8, 0, bytUtf8(0), _ lngUtf8Size, StrPtr(strBuffer), lngBufferSize) 'Trim result to actual length If lngResult Then UTF8_Decode = Left$(strBuffer, lngResult) End If End Function
把你上面获取的内容转一下就行,比如Text1.Text=UTF8_Decode(strResponse)
还可以加多一句InStr(1, strResponse, "charset=utf-8") > 0判断是否是UTF8编码再执行,不是UTF8的就直接显示。 还有些网页编码那里是大写的,要这样写InStr(1, strResponse, "charset=UTF-8") > 0
2014-03-06
展开全部
vb for android可以很方便转换,但只能做安卓软件
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询