vb 如何将Byte数组转换成字符串(兼容中英文)
展开全部
要看什么来源,如果byte数组数据本身是vb生成的,办法较简单。
Dim s As String
s = "中华人民共和国rePublic of China"
Dim b() As Byte
b = s' 直接赋值字节数组,每个字符都占两个字节
Debug.Print UBound(b)
Debug.Print CStr(b) '数组转换字符串也简单
b = StrConv(s, vbFromUnicode) '先转换为紧凑字符串赋给数组(英文字母只占一个字节)
Debug.Print UBound(b)
Debug.Print StrConv(b, vbUnicode) '数组转换为双字节字符串
Dim s As String
s = "中华人民共和国rePublic of China"
Dim b() As Byte
b = s' 直接赋值字节数组,每个字符都占两个字节
Debug.Print UBound(b)
Debug.Print CStr(b) '数组转换字符串也简单
b = StrConv(s, vbFromUnicode) '先转换为紧凑字符串赋给数组(英文字母只占一个字节)
Debug.Print UBound(b)
Debug.Print StrConv(b, vbUnicode) '数组转换为双字节字符串
展开全部
Private Function bytes2gb(b() As Byte) As String
Dim i As Integer
Dim by As Long
'判断中英文
For i = 0 To UBound(b)
by = b(i)
If b(i) >= 128 Then
by = 256 * by + b(i + 1) - 65536
i = i + 1
End If
bytes2gb = bytes2gb + Chr(by)
Next
End Function
Dim i As Integer
Dim by As Long
'判断中英文
For i = 0 To UBound(b)
by = b(i)
If b(i) >= 128 Then
by = 256 * by + b(i + 1) - 65536
i = i + 1
End If
bytes2gb = bytes2gb + Chr(by)
Next
End Function
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询