C# byte[] 如何去掉空值

        /// <summary>
        /// 去掉byte[] 中特定的byte 
        /// </summary>
        /// <param name="b">需要处理的byte[]</param>
        /// <param name="cut">byte[] 中需要除去的特定 byte (此处: byte cut = 0x00 ;) </param>
        /// <returns></returns>
        public byte[] ByteCut(byte[] b, byte cut) {
            var list = new List<byte>();
            list.AddRange(b);
            for (var i = list.Count - 1; i >= 0; i--) {
                if (list[i] == cut)
                    list.RemoveAt(i);
            }
            var lastbyte = new byte[list.Count];
            for (var i = 0; i < list.Count; i++) {
                lastbyte[i] = list[i];
            }
            return lastbyte;
        }

猜你喜欢

转载自blog.csdn.net/Qin066/article/details/84032461