0

I have got a string for instance:

"FF AA 1A 23 DF"

The only thing I want to get is a byte array that contains the following bytes:

[FF, AA, 1A, 23, DF..]

Somehow can I do a conversion like this?

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
Szaládi Tomi
  • 23
  • 1
  • 2

1 Answers1

6

Try Linq: Split and Convert

 string source = "FF AA 1A 23 DF";

 byte[] result = source
   .Split(' ')                               // Split into items 
   .Select(item => Convert.ToByte(item, 16)) // Convert each item into byte
   .ToArray();                               // Materialize as array
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215