How can I convert a hex string to a byte array?

I have a string representing a hexadecimal value: "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 that it looks something like this: {&H46, &HC9, &H8, &HB6, &HE8, &HF3, &H47, &HCF, &H53, &H2A, &H77, &H2, &HC9, &H19, &H7F}

How to do it?

+3


source to share


1 answer


Split the string and parse the hex numbers:



Dim bytes As Byte() = input.Split("-"c).Select(Function(n) Convert.ToByte(Convert.ToInt32(n, 16))).ToArray()

      

+2


source







All Articles