{0xaa,0x11,0x11,0xff}变成{0xaa,0x22,0xff}就是替换字节数组中的2个值,索引是不是要变?我for (int i = 0; i < b.Length-1; i++) b[i] = b[i + 1];好像不行啊,数组值的个数如何处理呢?谢谢我是处理里面指定的连续2个数,换成另外一个数。比如碰到“0x11,0x11”,就换成“0x02”谢谢各位了
喔,原先没注意题目,现在改了。连续两个相同替换的话替换:int i = 0, j = 0;byte[] myArr = { 0xaa, 0x11, 0x11, 0xff,0x11, 0x11, 0x21, 0x11 };byte[] myArr1 ={0x00} ;Array.Resize(ref myArr, myArr.Length+1);Array.Resize(ref myArr1, myArr.Length); for (; i < myArr.Length-1; i++) { if (myArr[i] == myArr[i + 1]) { myArr1[j] = 0x02; //当连续两个数相同时,用0x02替换 i++; } else { myArr1[j] = myArr[i]; //当连续两个数不同时不变 } j++; }Array.Resize (ref myArr1 ,j);myArr = myArr1; //完//