/// <summary> /// 去除byte[]数组缓冲区内的尾部空白区;从末尾向前判断; /// </summary> /// <param name="bytes"></param> /// <returns></returns> public byte[] bytesTrimEnd(byte[] bytes) { List<byte> list = bytes.ToList(); for (int i = bytes.Length - 1; i >= 0; i--) { if(bytes[i]==0x00) { list.RemoveAt(i); } else { break; } } return list.ToArray(); }
方法二
string recv = Encoding.Default.GetString(bytes); recv = recv.TrimEnd('\0');
标签:C#,0x00,bytes,list,数组,Byte,recv,byte From: https://www.cnblogs.com/dj1232090/p/17840304.html