vb.net 如何将十六进制字符串转换为字节数组?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14970436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I convert a Hexidecimal string to a Byte Array?
提问by user2089227
I have a string representing a hexidecimal value: "46-C9-08-B6-E8-F3-47-CF-53-2A-77-02-C9-19-7F"
我有一个表示十六进制值的字符串: "46-C9-08-B6-E8-F3-47-CF-53-2A-77-02-C9-19-7F"
I want to convert this to a byte array so it looks something like this: {&H46, &HC9, &H8, &HB6, &HE8, &HF3, &H47, &HCF, &H53, &H2A, &H77, &H2, &HC9, &H19, &H7F}
我想将其转换为字节数组,因此它看起来像这样: {&H46, &HC9, &H8, &HB6, &HE8, &HF3, &H47, &HCF, &H53, &H2A, &H77, &H2, &HC9, &H19, &H7F}
How do I do this?
我该怎么做呢?
回答by Guffa
Split the string and parse the hexadecimal numbers:
拆分字符串并解析十六进制数字:
Dim bytes As Byte() = input.Split("-"c).Select(Function(n) Convert.ToByte(Convert.ToInt32(n, 16))).ToArray()

