Skip to content

Instantly share code, notes, and snippets.

@EzioisAwesome56
Created September 17, 2021 14:07
Show Gist options
  • Save EzioisAwesome56/ccff9cdbfdbdceee56562bb3adcc845b to your computer and use it in GitHub Desktop.
Save EzioisAwesome56/ccff9cdbfdbdceee56562bb3adcc845b to your computer and use it in GitHub Desktop.
search byte array for another byte array
static int bytesFindIndexOfQuery(byte[] bytes, byte[] query) {
int bytesLen = bytes.length;
int queryLen = query.length;
int limitLen = (bytesLen - queryLen) + 1;
outer: for (int i = 0; i < limitLen; i++) {
for (int ii = 0; ii < queryLen; ii++) {
if (bytes[i + ii] != query[ii]) {
continue outer;
}
}
return i;
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment