string s = "01ac0c01"; MatchCollection matches = Regex.Matches(s, @"[0-9A-Fa-f]{2}"); byte[] bytes = new byte[matches.Count]; for (int i = 0; i < bytes.Length; i++) bytes[i] = byte.Parse(matches[i].Value, NumberStyles.AllowHexSpecifier);
string ss = "01ac0c01"; int len = ss.Length / 2; byte[] bs = new byte[len]; int j = 0; for (int i = 0; i < ss.Length; i += 2) { string str = ss.Substring(i, 2); bs[j] = (byte)int.Parse(str, System.Globalization.NumberStyles.HexNumber); j++; }
MatchCollection matches = Regex.Matches(s, @"[0-9A-Fa-f]{2}");
byte[] bytes = new byte[matches.Count];
for (int i = 0; i < bytes.Length; i++)
bytes[i] = byte.Parse(matches[i].Value, NumberStyles.AllowHexSpecifier);
int len = ss.Length / 2;
byte[] bs = new byte[len];
int j = 0;
for (int i = 0; i < ss.Length; i += 2)
{
string str = ss.Substring(i, 2);
bs[j] = (byte)int.Parse(str, System.Globalization.NumberStyles.HexNumber);
j++;
}