在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
代码如下: /// <summary> /// 去除byte数组头尾杂质(即不需要的数据) /// </summary> /// <param name="args"></param> static void Main(string[] args) { //---------------------去除头杂质--------------------------------- byte[] listTemp = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 0x55, 0xaa, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,7,8,8, 1, 4, 3, 2, 4, 6, 7, 8, 9, 2, 1, 0x55, 0xaa, 1, 2, 3, 4, 6 ,2 }; int index = 0; while (true) { if (listTemp[index] != 0x55 && listTemp[index++] != 0xaa) index++; else break; } byte[] listNew = new byte[listTemp.Length - index]; Array.Copy(listTemp, index, listNew, 0, listTemp.Length - index); int count = 10; List<byte> finaly = new List<byte>(); int lastStart = listNew.ToList<byte>().LastIndexOf(0x55); if (listNew[lastStart + 1] == 0xaa) { if ((listNew.Length) - (lastStart + 1) != count) { byte[] listFinaly = new byte[lastStart]; //listFinaly 此处数组就是剔除了头尾杂质的 Array.Copy(listNew, 0, listFinaly, 0, lastStart); finaly = listFinaly.ToList<byte>(); } } Console.ReadLine(); }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论