首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

怎样将汉字转为UTF8的乱码?该如何处理

2012-01-03 
怎样将汉字转为UTF8的乱码?rt[解决办法]http://www.google.cn/search?qdeclare+multibytetowidechar+utf8

怎样将汉字转为UTF8的乱码?
rt

[解决办法]
http://www.google.cn/search?q=declare+multibytetowidechar+utf8&complete=1&hl=zh-CN&newwindow=1
[解决办法]
http://tlcheng.twbbs.org/TLCheng/Net/vb/MyStdInclude/Module/StrTools.txt
[解决办法]
Public Function Str_UTF_8(ByVal Str_GB As String, Optional ByVal Sytle As String = "string ") As String

Dim Source() As Byte
Dim UTF_16 As Long
Dim Str_Bin As String
Dim My_utf_Bin As String
Dim Str_chr As String
Dim UTF_VAL As Long
Dim Str_hex As String
Dim Str_utf_hex As String


For j = 1 To Len(Str_GB)
CopyMemory UTF_VAL, ByVal StrPtr(Mid(Str_GB, j, 1)), 2 '得到unicode码

Str_hex = Hex(UTF_VAL) '转为16进制字符串
Str_Bin = H_To_B(Str_hex, 16) '转为2进制字符串

If UTF_VAL < &H80 Then ' 1 UTF-8 byte
My_utf_Bin = Mid(Str_Bin, 9, 8)

ElseIf UTF_VAL < &H800 Then ' 2 UTF-8 bytes
My_utf_Bin = "110 " + Mid(Str_Bin, 5, 5) + "10 " + Mid(Str_Bin, 11, 6)

Else ' 3 UTF-8 bytes
My_utf_Bin = "1110 " + Mid(Str_Bin, 1, 4) + "10 " + Mid(Str_Bin, 5, 6) + "10 " + Mid(Str_Bin, 11, 6)

end function

热点排行