如何将包含十六进制值的ascii表示的字符串复制/转换为包含实际十六进制值的字节数组?例如,我有一个包含由空格分隔的十六进制值的变量(我可以更改分隔符):
myString =“24 01 66 09 13 2F 1E 00 00 4E”
我想将这些值放入字节数组中:
将myByteArr(9)变为Byte
答案 0 :(得分:2)
Public Shared Function HexToBytes(ByVal s As String) As Byte()
Dim bytes As String() = s.Split(" "c)
Dim retval(bytes.Length - 1) As Byte
For ix As Integer = 0 To bytes.Length - 1
retval(ix) = Byte.Parse(bytes(ix), System.Globalization.NumberStyles.HexNumber)
Next
Return retval
End Function