|
-
Jun 12th, 2005, 01:23 AM
#1
[Resolved] Search a BYTE Array
Is there a function that can search a byte array for a series of bytes or a string?
Last edited by randem; Jun 30th, 2005 at 01:30 PM.
-
Jun 12th, 2005, 01:27 AM
#2
Re: Search a BYTE Array
Don't think so, I suppose you could turn it into a string somehow and use InStr but otherwise I would use a loop and search every so many bytes for the sequence you're looking for.
-
Jun 12th, 2005, 01:32 AM
#3
Re: Search a BYTE Array
penagate,
Thanks, StrConv seems to only like text and my array can contain anything. I guess I will have to write one.
-
Jun 12th, 2005, 01:37 AM
#4
Re: Search a BYTE Array
Maybe you could do this?
VB Code:
Dim strTemp As String
strTemp = Space(UBound(ByteArray))
CopyMemory ByVal strTemp, ByteArray(0), UBound(ByteArray)
Although since strings are wide I'm not sure if that would work, you might have to insert zero bytes at every odd interval.
-
Jun 12th, 2005, 02:07 AM
#5
Re: Search a BYTE Array
Here:
VB Code:
Option Explicit
Private Sub Form_Load()
Dim A(-1 To 10) As Byte, B(5 To 7) As Byte
A(-1) = 100
A(0) = 5
A(1) = 6
A(2) = 67
A(3) = 3
A(4) = 34
A(5) = 76
A(6) = 12
A(7) = 34
A(8) = 2
A(9) = 1
A(10) = 99
B(5) = 12
B(6) = 34
B(7) = 2
Debug.Print SearchByteArray(A, B, -888)
End Sub
Public Function SearchByteArray(BigArr() As Byte, SearchArr() As Byte, Optional ByVal NotFoundRet As Long = -1) As Long
Dim K As Long, Q As Long, LB As Long
LB = LBound(SearchArr)
For K = LBound(BigArr) To UBound(BigArr) - (UBound(SearchArr) - LB)
For Q = LB To UBound(SearchArr)
If BigArr(K + Q - LB) <> SearchArr(Q) Then Exit For
Next Q
If Q = UBound(SearchArr) + 1 Then Exit For
Next K
If K <= UBound(BigArr) - (UBound(SearchArr) - LB) Then
SearchByteArray = K
Else
SearchByteArray = NotFoundRet
End If
End Function
Should I put this in the CodeBank ? i think I should right ?
Last edited by CVMichael; Jun 12th, 2005 at 02:15 AM.
-
Jun 12th, 2005, 02:37 AM
#6
Re: Search a BYTE Array
By the way... when you do InStr in VB, in the background, that's how it does the search...
-
Jun 12th, 2005, 02:41 AM
#7
Re: Search a BYTE Array
I thought as much, but its written in C or something, so it's a fair bit quicker than anything we could write ourselves in VB.
-
Jun 12th, 2005, 02:42 AM
#8
Re: Search a BYTE Array
 Originally Posted by penagate
I thought as much, but its written in C or something, so it's a fair bit quicker than anything we could write ourselves in VB.
YUP
-
Jun 12th, 2005, 01:39 PM
#9
Re: Search a BYTE Array
I wrote the routine but it if god-awful slow. It is not an option.
-
Jun 12th, 2005, 01:59 PM
#10
Re: Search a BYTE Array
 Originally Posted by randem
I wrote the routine but it if god-awful slow. It is not an option.
Did you try CVMichael's code a few posts back?
Cheers,
RyanJ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|