Mega Code Archive

 
Categories / C# / Data Types
 

Byte array Index Of

//GNU General Public License version 2 (GPLv2) //http://walkmen.codeplex.com/license using System; using System.Collections.Generic; using System.Text; namespace Walkmen.Util {     public sealed class ByteUtils     {         private ByteUtils()         {         }         public static int IndexOf(byte[] array, byte[] pattern, int offset)         {             int success = 0;             for (int i = offset; i < array.Length; i++)             {                 if (array[i] == pattern[success])                 {                     success++;                 }                 else                 {                     success = 0;                 }                 if (pattern.Length == success)                 {                     return i - pattern.Length + 1;                 }             }             return -1;         }     } }