字符串string s="0xaa 0x01 0x23 0xff"分割字符串后,如何存储到字节数据中?
我只得得出字符串数据,分别存储string[]result={"0xaa","0x01","0x23","0xff"},转化存储到byte[]bb时有问题...
我只得得出字符串数据,分别存储string[] result={"0xaa ","0x01 ","0x23 ","0xff"},转化存储到byte[]bb时有问题
展开
2个回答
展开全部
string s = "0xaa 0x01 0x23 0xff";
string[] strArray = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
byte[] binArray = new byte[strArray.Length];
for (int i = 0; i < binArray.Length; i++)
{
binArray[i] = byte.Parse(strArray[i].Substring(2), System.Globalization.NumberStyles.HexNumber);
}
string[] strArray = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
byte[] binArray = new byte[strArray.Length];
for (int i = 0; i < binArray.Length; i++)
{
binArray[i] = byte.Parse(strArray[i].Substring(2), System.Globalization.NumberStyles.HexNumber);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询