[color=#FF0000][b]恭请大牛:byte() 转 unicode字符串 高效且线程安全 strconv的替代方法[/b][/color]
程序代码片段:Dim source(3) As Byte
Dim target as string
source(0) = 97
source(1) = 98
source(2) = 99
source(3) = 100
如何让 target的值成为 “abcd” 而不是乱码“扡摣”
代码在多线程中运行所以不能使用strconv
考虑到效率不要循环遍历的方法
本人在使用MultiByteToWideChar 和CopyMemory进行测试没有成功,有木有高手施展一下? --------------------编程问答-------------------- 沙发!我就知道StrConv。。。 --------------------编程问答--------------------
Dim source(8) As Byte
Dim target As String
source(1) = 0
source(0) = 97
source(3) = 0
source(2) = 98
source(5) = 0
source(4) = 99
source(7) = 0
source(6) = 100
s = source
遍历了
其实我是来签到的 --------------------编程问答-------------------- --------------------编程问答--------------------
--------------------编程问答--------------------
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 Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long
Function ConvToUnicode(iStr() As Byte) As String
Const CP_ACP = 0&
Dim iLen As Long
iLen = lstrlen(VarPtr(iStr(0))) + 2&
ConvToUnicode = String$(iLen, 0)
iLen = MultiByteToWideChar(CP_ACP, 0&, VarPtr(iStr(0)), -1&, StrPtr(ConvToUnicode), iLen)
ConvToUnicode = Left$(ConvToUnicode, iLen - 1&)
End Function
Private Sub Command1_Click()
Dim source(3) As Byte
Dim target As String
source(0) = 97
source(1) = 98
source(2) = 99
source(3) = 100
target = ConvToUnicode(source)
Print target
End Sub
收藏了
不过运行有乱码
abcd?
abcd?
abcd?
abcd?
把Dim source(3) As Byte改成Dim source(4) As Byte就没有乱码了
--------------------编程问答--------------------
有可能会有乱码,原因是lstrlen正常应该返回一个以\0结束的字符串的长度。
--------------------编程问答--------------------
学习
补充:VB , 网络编程