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的示例代码的详细内容。
