By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,813 Members | 2,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,813 IT Pros & Developers. It's quick & easy.

Best way to search an array for a value and return offset position

P: 3
I have a binary file loaded into a byte array (which might need to be converted to a string). I am trying to enter a value in Txtbx2 and search the array, when found return the offset where it was found. Is there a way I can alter the code below to work or is there another way?

Expand|Select|Wrap|Line Numbers
  1. Dim [Data] As Byte() = New Byte() {1, 2, 4, 6, 3}
  2.         Dim find As Byte = TextBox2.Text
  3.         Dim index As Integer = System.Array.IndexOf(Of Byte)([Data], find)
  4.  
  5.         If (index = -1) Then
  6.             MessageBox.Show("Not Found")
  7.             'Not found...
  8.         Else
  9.             'Found
  10.             TextBox3.Text = index
  11.         End If  
Oct 22 '14 #1
Share this Question
Share on Google+
4 Replies


iam_clint
Expert 100+
P: 1,208
Are you trying to find a byte array or an individual byte? or what are you trying to accomplish really?
Oct 22 '14 #2

P: 3
Im trying to search a byte array for a particular byte and then return the offset where it is located and do so for every instance that specific byte is used in a binary file
Oct 23 '14 #3

P: 10
If you want to search many times, you may sort it and perform binary search.
Oct 23 '14 #4

P: 3
I figured out how to return the decimal offset or block. Now I have to figure out how to loop it to continue searching, and how to properly print the output
Oct 23 '14 #5

Post your reply

Sign in to post your reply or Sign up for a free account.