简体   繁体   English

在另一个字节数组中查找字节数组并提取 x 字节数

[英]Find byte array inside another byte array and extract x amount of bytes

Any idea how I can find a byte array inside a byte array?知道如何在字节数组中找到字节数组吗?

Example例子

byte[] array1 = { 101, 21, 92, 1, 92, 0, 132, 0, 22 }
byte[] search = { 21, 92 }

so use array search and find it inside array1 then extract x amount of bytes after the search array up until specific bytes are reached such as,所以使用数组搜索并在 array1 中找到它,然后在搜索数组之后提取 x 字节数,直到达到特定字节,例如,

0, 132, 0, 22

Extraction for example would be in this scenario例如提取将在这种情况下

1, 92

from array1来自array1

byte[] array1 = { 101, 21, 92, 1, 92, 0, 132, 21, 0, 22 };
byte[] search = { 21, 92 };
var data = search.Where(a => array1.Contains(a)).ToList();
foreach (var item in data)
{
    Console.WriteLine(item);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM