请教VB6字符串如何转化为16进制BYTE数组
1个回答
展开全部
VB字符串可通过使用StrConv 函数,将字符串由 Unicode 转成系统的缺省码页后,再获取每个字节的十六进制字符后拼接起来。
StrConv 函数,返回按指定类型转换的 Variant (String)。
实现代码:
Private Sub Command1_Click()
Dim strSj As String
Dim strHexSj As String
Dim i As Long
Dim bytSj() As Byte
strSj = "123ABC十六进制"
bytSj = StrConv(strSj, vbFromUnicode)
For i = 0 To UBound(bytSj)
strHexSj = strHexSj & Right("0" & Hex(bytSj(i)), 2)
Next
Debug.Print strHexSj
End Sub
StrConv 函数,返回按指定类型转换的 Variant (String)。
实现代码:
Private Sub Command1_Click()
Dim strSj As String
Dim strHexSj As String
Dim i As Long
Dim bytSj() As Byte
strSj = "123ABC十六进制"
bytSj = StrConv(strSj, vbFromUnicode)
For i = 0 To UBound(bytSj)
strHexSj = strHexSj & Right("0" & Hex(bytSj(i)), 2)
Next
Debug.Print strHexSj
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询