问题描述
我有一个十六进制值,
我想转换为一个字节数组。
.NET 3.5中有一个内置函数可以完成工作吗?需要编写一个函数来循环每个字符串中的每一对,并将其转换为它的8位整数等价?
我有一个十六进制值,
我想转换为一个字节数组。
.NET 3.5中有一个内置函数可以完成工作吗?需要编写一个函数来循环每个字符串中的每一对,并将其转换为它的8位整数等价?
没有内置的功能可以做到这一点。你将不得不编码一个:($ / $>
Public Function ToHexList(ByVal str As String)As List(Of Byte)
Dim list As New List(Byte)
For i = 0 to str.Length-1 Step 2
list.Add(Byte.Parse(str.SubString(i,2),Globalization .NumberStyles.HexNumber))
下一个
返回列表
结束函数
编辑
使用Globalization名称空间限定符限定NumberStyles枚举。另一个选项是导入该名称空间并删除限定符。 >
I have a hexadecimal value,
Which I want to convert to a byte array.
Is there a built-in function in .NET 3.5 that will get the job done or will I need to write a function to loop through each pair in the string and convert it to its 8-bit integer equivalent?
There is no built-in function that will do this. You will unfortunately have to code one up :(
Public Function ToHexList(ByVal str As String) As List(Of Byte)
Dim list As New List(Of Byte)
For i = 0 to str.Length-1 Step 2
list.Add(Byte.Parse(str.SubString(i,2), Globalization.NumberStyles.HexNumber))
Next
Return list
End Function
EDIT
Qualified the NumberStyles enumeration with the Globalization namespace qualifier. Another option is to import that namespace and remove the qualifier.
这篇关于VB.NET中的十六进制到8位无符号数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!