本文为 testcs_dn(微wx笑) 原创文章
转载连接: http://blog.csdn.net/testcs_dn/article/details/25277005
C#二进制字节数组操作函数 截取字节数组SubByte
-
-
-
-
-
-
-
- public byte[] SubByte(byte[] srcBytes, int startIndex, int length)
- {
- System.IO.MemoryStream bufferStream = new System.IO.MemoryStream();
- byte[] returnByte = new byte[] { };
- if (srcBytes == null) { return returnByte; }
- if (startIndex < 0) { startIndex = 0; }
- if (startIndex < srcBytes.Length)
- {
- if (length < 1 || length > srcBytes.Length - startIndex) { length = srcBytes.Length - startIndex; }
- bufferStream.Write(srcBytes, startIndex, length);
- returnByte = bufferStream.ToArray();
- bufferStream.SetLength(0);
- bufferStream.Position = 0;
- }
- bufferStream.Close();
- bufferStream.Dispose();
- return returnByte;
- }