VB UTF-8 问题
答案:3 悬赏:0 手机版
解决时间 2021-04-02 16:13
- 提问者网友:轻浮
- 2021-04-01 20:32
VB UTF-8 问题
最佳答案
- 五星知识达人网友:酒醒三更
- 2021-04-01 21:05
Private 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 String, ByVal lpUsedDefaultChar As Long) As Long
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
Private Const CP_UTF8 = 65001
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(0)), lLength, StrPtr(Utf8ToUnicode), lBufferSize)
If lRet <> 0 Then
Utf8ToUnicode = Left(Utf8ToUnicode, lRet)
End If
End Function
Private Sub Form_Load()
Dim a As String
Dim b() As Byte
Dim i As Integer
a = "E9 A2 91 E9 81 93 31 00"
ReDim b(UBound(Split(a, " ")) - 1) As Byte
For i = 0 To UBound(Split(a, " ")) - 1
b(i) = "&H" & Split(a, " ")(i)
Next i
Text1.Text = Utf8ToUnicode(b())
End Sub
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
Private Const CP_UTF8 = 65001
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(0)), lLength, StrPtr(Utf8ToUnicode), lBufferSize)
If lRet <> 0 Then
Utf8ToUnicode = Left(Utf8ToUnicode, lRet)
End If
End Function
Private Sub Form_Load()
Dim a As String
Dim b() As Byte
Dim i As Integer
a = "E9 A2 91 E9 81 93 31 00"
ReDim b(UBound(Split(a, " ")) - 1) As Byte
For i = 0 To UBound(Split(a, " ")) - 1
b(i) = "&H" & Split(a, " ")(i)
Next i
Text1.Text = Utf8ToUnicode(b())
End Sub
全部回答
- 1楼网友:独钓一江月
- 2021-04-01 22:59
1.没考虑过
2. FileOpen(1, "", OpenMode.Binary)'VB.NEt2010的代码..VB6也应该差不多
3.请吧单双字节考虑进去,否则还是以二进制的方法读取文件
4.没考虑过,不过文字本质都是些图片不转换用不了吧
2. FileOpen(1, "", OpenMode.Binary)'VB.NEt2010的代码..VB6也应该差不多
3.请吧单双字节考虑进去,否则还是以二进制的方法读取文件
4.没考虑过,不过文字本质都是些图片不转换用不了吧
- 2楼网友:妄饮晩冬酒
- 2021-04-01 22:16
尝试用 StrConv() 函数看有没有帮助,例如:
FileName = StrConv(UFileName, vbFromUnicode)
再不就要研究一下相关的 Windows API 了...
FileName = StrConv(UFileName, vbFromUnicode)
再不就要研究一下相关的 Windows API 了...
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯