KRC
KRC

Reputation: 328

Accessing an array in VB.NET

I am receiving an array of bytes periodically, of irregular size. What i am looking for is a specific size, since each received message has a consistent size of 27 bytes. It looks something like this:

"0 2 0 ....... XX 0"

so sometimes the received array will look like this "0 0 2 .... "

I can use the BinarySearch function in http://msdn.microsoft.com/en-us/library/aa310858(v=vs.71).aspx

to help me identify the index of the first zero i find, then check if the next byte is 2. However, if that's not the case, i move on to the next index, and continue checking and so on. But it seems to me like this isn't a good way, and is going to lead to some messy code. Does anybody have a better idea to help me identify the start of a read byte?

Upvotes: 1

Views: 119

Answers (1)

xpda
xpda

Reputation: 15813

Since it's an array of bytes, it would be easy to scan the array with a for loop.

for i as integer = 0 to ubound(bytearray)-1
  if bytearray(i) = 0 andalso bytearray(i+1) = 2 then ...

Upvotes: 1

Related Questions