0

How can I efficiently find the location of the first instance of a four byte sequence within a byte array? Is there something more efficient than looping through the whole array, or a built-in method?

I'm searching through a byte array for a pair of CrLF. I can't convert it to string for an InStr first because I need the position of it in the original byte array.

I am trying to figure out the location of this, as it delimits between a string portion and a binary portion, similar (well, exactly like for this part of it) to an HTTP header. There is a string portion, and two CrLf before the content begins.

1

2 Answers 2

1

You may use Boyer-Moore's algorithm, which is better than linear in the average.

HTH!

Sign up to request clarification or add additional context in comments.

Comments

1

Assuming nothing about the data set (sorted/special ordering) the best you can do is an O(n) algorithm, which means looking through the whole array once.

1 Comment

Ok, that answers my question. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.