您当前的位置: 首页 >  c#

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

发布时间:2014-05-08 09:24:25 ,浏览量:0

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

    }
关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    109276博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0494s