Answer the question
In order to leave comments, you need to log in
Is there a handy function in c# to find a byte array inside another byte array?
for (int i = 0; i < fs.Length; i++)
{
if (fs[i] == 64)
{
if (fs[i + 1] == 115)
{
if (fs[i + 2] == 46)
{
if (fs[i + 3] == 119)
{
if (fs[i + 4] == 104)
{
if (fs[i + 5] == 97)
{
if (fs[i + 6] == 116)
{
if (fs[i + 7] == 115)
{
if (fs[i + 8] == 97)
{
byte[] noom = { fs[i - 11], fs[i - 10], fs[i - 9], fs[i - 8], fs[i - 7], fs[i - 6], fs[i - 5], fs[i - 4], fs[i - 3], fs[i - 2], fs[i - 1] };
string str = Encoding.UTF8.GetString(noom, 0, noom.Length);
if (Convert.ToInt64(str) > 0)
{
numbers.Add(str);
}
}
}
}
}
}
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
??
static int SearchBytes( byte[] haystack, byte[] needle ) {
var len = needle.Length;
var limit = haystack.Length - len;
for( var i = 0; i <= limit; i++ ) {
var k = 0;
for( ; k < len; k++ ) {
if( needle[k] != haystack[i+k] ) break;
}
if( k == len ) return i;
}
return -1;
}
public bool IsContains(this byte[] arr1, byte[] arr2)
{
if (arr1.Intersect(arr2).Count() != 0)
return true;
return false;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question