c++ and c# convert byte-string
I am dealing with a problem. I have a string "00-C4-D3-EC-12-45". 开发者_如何学编程I want to fill an array of bytes with this values. How to do it? I mean ..an byte[] x= new byte [6] to have the values: 0x00, 0xC4; 0xD3...and so on. Need a solution. THX
"00-C4-D3-EC-12-45".Split('-').Select(s=>Convert.ToByte(s, 16)).ToArray();
Or without LINQ:
string[] parts="00-C4-D3-EC-12-45".Split('-');
byte[] bytes=new byte[parts.Length];
for(int i=0;i<bytes.Length;i++)
bytes[i]=Convert.ToByte(parts[i], 16);
精彩评论