• Web sitemizin içeriğine ve tüm hizmetlerimize erişim sağlamak için Web sitemize kayıt olmalı ya da giriş yapmalısınız. Web sitemize üye olmak tamamen ücretsizdir.
  • Sohbetokey.com ile canlı okey oynamaya ne dersin? Hem sohbet et, hem mobil okey oyna!
  • Soru mu? Sorun mu? ''Bir Sorum Var?'' sistemimiz aktiftir. Paylaşın beraber çözüm üretelim.

Byte Array'da Index Araması

Üyelik Tarihi
7 Ocak 2015
Konular
4,091
Mesajlar
4,274
MFC Puanı
40
Kod:
Bu dersimizde C# Byte Array'da index araması yapmayı öğreneceğiz.

static int FindIndex(byte[] source, byte[] search)
{
if(source.Length == 0 || search.Length == 0 ||
source == null || search == null || search.Length > source.Length) return -1;

for (int i = 0; i < source.Length; i++)
{
int toplam = 0;

for (int i2 = 0; i2 < search.Length; i2++)
{
if (source[i] == search[i2]) 
{ 
toplam++;
if (i++ > source.Length - 2) break;
}
else break;
}

if (toplam == search.Length) return i - search.Length;
}

return -1;
}



// Örnek

byte[] source = new byte[] { 4,81,244,55,66,88,101 };
byte[] search = new byte[] { 55,66,88 };

int ret = FindIndex(source, search);

// ret = 3
 
Üst