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

本文为 testcs_dn(微wx笑) 原创文章   

转载连接: http://blog.csdn.net/testcs_dn/article/details/25277005


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

[csharp]  view plain  copy
  1. /// <summary>  
  2. /// 截取字节数组  
  3. /// </summary>  
  4. /// <param name="srcBytes">要截取的字节数组</param>  
  5. /// <param name="startIndex">开始截取位置的索引</param>  
  6. /// <param name="length">要截取的字节长度</param>  
  7. /// <returns>截取后的字节数组</returns>  
  8. public byte[] SubByte(byte[] srcBytes, int startIndex, int length)  
  9. {  
  10.     System.IO.MemoryStream bufferStream = new System.IO.MemoryStream();  
  11.     byte[] returnByte = new byte[] { };  
  12.     if (srcBytes == null) { return returnByte; }  
  13.     if (startIndex < 0) { startIndex = 0; }  
  14.     if (startIndex < srcBytes.Length)  
  15.     {  
  16.         if (length < 1 || length > srcBytes.Length - startIndex) { length = srcBytes.Length - startIndex; }  
  17.         bufferStream.Write(srcBytes, startIndex, length);  
  18.         returnByte = bufferStream.ToArray();  
  19.         bufferStream.SetLength(0);  
  20.         bufferStream.Position = 0;  
  21.     }  
  22.     bufferStream.Close();  
  23.     bufferStream.Dispose();  
  24.     return returnByte;  
  25. }  

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值