先遍歷數(shù)組:
創(chuàng)新互聯(lián)是一家專注于成都做網(wǎng)站、網(wǎng)站建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)與策劃設(shè)計(jì),鶴慶網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)十多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:鶴慶等地區(qū)。鶴慶做網(wǎng)站價格咨詢:13518219792
for?i?=?0?to?Ubound(數(shù)組)
...
next
再把中間的...替換成:
if?數(shù)組(i)?=?特定的字符?then?msgbox?"找到鳥,當(dāng)前是:數(shù)組"??i
Public?Class?Form1
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
Dim?a()?As?Byte?=?System.IO.File.ReadAllBytes("record.db")
For?Index?As?Integer?=?a.GetLowerBound(0)?To?a.GetUpperBound(0)?-?3
If?a(Index)?=?56?AndAlso?a(Index?+?1)?=?57?AndAlso?a(Index?+?2)?=?58?AndAlso?a(Index?+?3)?=?59?Then
Debug.Print(Index.ToString)?'輸出byte串位置
End?If
Next
End?Sub
End?Class
剛學(xué),不知道有沒有直接在數(shù)組中搜索一串元素的方法。
'''這個函數(shù)功能就是用來把數(shù)組轉(zhuǎn)為string的格式'''如byte()={1,2,3,4,5,6}轉(zhuǎn)化后變?yōu)?,1,2,3,4,5,6,"Function ByteArrayToString(bytes() As Byte) As String Dim s As String = "" For i As Integer = 0 To bytes.Length s = Convert.ToString(bytes(i)) "," Next Return “," sEnd Function Sub Search()Dim a as byte()={1,2,3,4,5,6}
Dim b as byte()={2,3,4}
Dim astr As String = ByteArrayToString(a)Dim bstr As String = ByteArrayToString(b)Dim index As Integer = astr.IndexOf(bstr) '這個index就是b數(shù)組在a數(shù)組的位置,下標(biāo)從0開始,不過記得處理下逗號,因?yàn)檫@時候是字符串。'''如果index小于0說明沒有匹配內(nèi)容End Sub 現(xiàn)在說明下ByteArrayToString為什么要在字符串開頭加個",",如果不加,可能出現(xiàn)a="1,23,4,5,6,", b="3,4,5,",結(jié)果導(dǎo)致查詢位置錯誤,匹配了a的位置