- PrivateDeclareFunctionMultiByteToWideCharLib"kernel32"(ByValCodePageAsLong,ByValdwFlagsAsLong,ByReflpMultiByteStrAsAny,ByValcchMultiByteAsLong,ByVallpWideCharStrAsLong,ByValcchWideCharAsLong)AsLong
- PrivateConstCP_UTF8=65001
- 'Purpose:ConvertUtf8toUnicode
- PublicFunctionUTF8_Decode(ByValsUTF8AsString)AsString
- DimlngUtf8SizeAsLong
- DimstrBufferAsString
- DimlngBufferSizeAsLong
- DimlngResultAsLong
- DimbytUtf8()AsByte
- DimnAsLong
- IfLenB(sUTF8)=0ThenExitFunction
- OnErrorGoToEndFunction
- bytUtf8=StrConv(sUTF8,vbFromUnicode)
- lngUtf8Size=UBound(bytUtf8)+1
- OnErrorGoTo0
- lngBufferSize=lngUtf8Size*2
- strBuffer=String$(lngBufferSize,vbNullChar)
- 'Translateusingcodepage65001(UTF-8)
- lngResult=MultiByteToWideChar(CP_UTF8,bytUtf8(0),_
- lngUtf8Size,StrPtr(strBuffer),lngBufferSize)
- 'Trimresulttoactuallength
- IflngResultThen
- UTF8_Decode=Left$(strBuffer,lngResult)
- EndIf
- EndFunction
把你上面获取的内容转一下就行,比如Text1.Text=UTF8_Decode(strResponse) 还可以加多一句InStr(1,strResponse,"charset=utf-8") > 0判断是否是UTF8编码再执行,不是UTF8的就直接显示。 还有些网页编码那里是大写的,要这样写InStr(1,"charset=UTF-8") > 0
原文链接:https://www.f2er.com/vb/260595.html