All pastes #908187 Raw Edit

Untitled

public text v1 · immutable
·published 2008-02-18 05:19 UTC
rendered paste body
    private int arrayFind(byte[] haystack, byte[] needle)
    {
      int i = Array.IndexOf(haystack, needle[0]);
      while (i > -1)
      {
        for (int j = 0; j < needle.Length && (j + i) < haystack.Length; j++)
        {
          if (needle[j] != haystack[i + j]) break;
          if (j == needle.Length - 1) return i;
        }
        i = Array.IndexOf(haystack, needle[0], i + 1);
      }
      return -1;
    }