截取字节数组
/// <summary> /// 截取字节数组 /// </summary> /// <param name="srcBytes">要截取的字节数组</param> /// <param name="startIndex">开始截取位置的索引</param> /// <param name="length">要截取的字节长度</param> /// <returns>截取后的字节数组</returns> 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; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。