码迷,mamicode.com
首页 > 其他好文 > 详细

C#二进制字节数组操作函数 截取字节数组SubByte

时间:2014-05-08 11:15:21      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:c#   二进制   字节数组   截取   subbyte   

C#二进制字节数组操作函数 截取字节数组SubByte

        /// <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;
        }

    }

C#二进制字节数组操作函数 截取字节数组SubByte,布布扣,bubuko.com

C#二进制字节数组操作函数 截取字节数组SubByte

标签:c#   二进制   字节数组   截取   subbyte   

原文地址:http://blog.csdn.net/testcs_dn/article/details/25277005

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!