473,326 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Searching Byte Array

I have a Byte Array

Dim A1() as byte = {1,2,3,4,9,9,9,11,12,13,14,9,9,9}

I want to find the location of the first occurance of the byte sequence
{9,9,9}.

Is there a built in Framework class that will do this easily?
I've tried messing with Array.IndexOf but can't seem to get it to
indicate where the byte sequnce starts.

Any help greatly appreciated.

Larry
Nov 21 '05 #1
2 4597
You can convert the byte array into a string of characters then use the
string functions to search, i.e., .Indexof

"Larry" wrote:
I have a Byte Array

Dim A1() as byte = {1,2,3,4,9,9,9,11,12,13,14,9,9,9}

I want to find the location of the first occurance of the byte sequence
{9,9,9}.

Is there a built in Framework class that will do this easily?
I've tried messing with Array.IndexOf but can't seem to get it to
indicate where the byte sequnce starts.

Any help greatly appreciated.

Larry

Nov 21 '05 #2
Larry,
| Is there a built in Framework class that will do this easily?

There is no builtin function that I know of per se, however you could create
your own something like:

Public Function FindSequence(ByVal list() As Byte, ByVal value() As Byte)
As Integer
Dim startIndex As Integer = Array.IndexOf(list, value(0))
Do Until startIndex = -1 OrElse list.Length - startIndex <
value.Length
Dim runLength As Integer = 0
For index As Integer = 0 To value.Length - 1
If value(index) <> list(startIndex + index) Then Exit For
runLength += 1
Next
If runLength = value.Length Then Return startIndex
startIndex = Array.IndexOf(list, value(0), startIndex +
runLength)
Loop
Return -1
End Function
Dim A1() As Byte = {1, 2, 3, 4, 9, 9, 9, 11, 12, 13, 14, 9, 9, 9}
Dim value() As Byte = {9, 9, 9}

Dim index As Integer = FindSequence(A1, value)
Hope this helps
Jay
"Larry" <la***@larry.com> wrote in message
news:Lgsae.10033$c24.2165@attbi_s72...
|I have a Byte Array
|
| Dim A1() as byte = {1,2,3,4,9,9,9,11,12,13,14,9,9,9}
|
| I want to find the location of the first occurance of the byte sequence
| {9,9,9}.
|
| Is there a built in Framework class that will do this easily?
| I've tried messing with Array.IndexOf but can't seem to get it to
| indicate where the byte sequnce starts.
|
| Any help greatly appreciated.
|
| Larry
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Richard Berg | last post by:
Hello, I need to search a byte array for a sequence of bytes. The sequence may include wildcards. For example if the array contains 0xAA, 0xBB, 0xAA, OxDD then I want to be able to search for...
16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
15
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
11
by: chaitali.pats | last post by:
Hi , I have implemented MD5 in C language . I am getting an output of 32 bits Hexadecimal number . for example : 83a80d3ca057492f0ce99ac1db8dced0 I need to convert this string same to 16...
8
by: tbh | last post by:
for historical reasons i need to be able to call, from C# under DotNet 2, as COM+ DLL function that returns a "string" which is really an array of seemingly arbitrary bytes (presumably non-zero)....
10
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it...
9
by: ssubbarayan | last post by:
Hi all, I am trying a program to convert floating point values to a byte array and printing the same to the screen.The idea behind this is we already have an existing function which can do byte...
2
by: zeroonea | last post by:
hi there, i playing around with an async server, i use BeginReceive with byte array to store incoming data, when a "big" data come, a call back receive can not read it all in one time, so i need...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.