vb6.0 控件加载utf-8格式的文件出现乱码
不管用什么方法读文件到控件都出现乱码
richtextbox,textbox都一样,如何解决?!求各位大神帮帮小弟!!!
[解决办法]
将UTF-8转为GB2312,网上有代码的。
[解决办法]
转换吧 http://download.csdn.net/source/3147493
[解决办法]
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 LongPrivate Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long'常用的代码页:const cpUTF8 =65001const cpGB2312 = 936const cpGB18030=54936const cpUTF7 =65000Function MultiByteToUTF16(UTF8() As Byte, CodePage As Long) As String Dim bufSize As Long bufSize = MultiByteToWideChar(CodePage, 0&, UTF8(0), UBound(UTF8) + 1, 0, 0) MultiByteToUTF16 = Space(bufSize) MultiByteToWideChar CodePage, 0&, UTF8(0), UBound(UTF8) + 1, StrPtr(MultiByteToUTF16), bufSizeEnd FunctionFunction UTF16ToMultiByte(UTF16 As String, CodePage As Long) As Byte() Dim bufSize As Long Dim arr() As Byte bufSize = WideCharToMultiByte(CodePage, 0&, StrPtr(UTF16), Len(UTF16), 0, 0, 0, 0) ReDim arr(bufSize - 1) WideCharToMultiByte CodePage, 0&, StrPtr(UTF16), Len(UTF16), arr(0), bufSize, 0, 0 UTF16ToMultiByte = arrEnd FunctionPrivate Sub Command1_Click() MsgBox MultiByteToUTF16(UTF16ToMultiByte("ab中,c", cpUTF8), cpUTF8)End Sub
[解决办法]
直接赋值
string s
byte() b()
s= b() 即可
[解决办法]
Dim aBytes() As Byte,s as string
......
s = StrConv(aBytes, vbUnicode)
[解决办法]
要先用二进制的方法,将数据读到Byte数组中,然后再4楼的方法转换。