搜索字节数组

时间:2013-01-11 12:26:06

标签: vb.net

基本上我在VB.NET中搜索一个字节数组,使用以下代码:

For i As Integer = 0 To message.Length - 1
    If message(i) = Asc(ControlChars.Cr) Then
        If message(i + 1) = Asc(ControlChars.Lf) Then
            If message(i + 2) = Asc(ControlChars.Cr) Then
                If message(i + 3) = Asc(ControlChars.Lf) Then
                    start = i + 4 ' take into account the above characters
                    Exit For
                End If
            End If
        End If
    End If
Next

Dim length As Integer = message.Length - start

我想知道是否有更好的方法可以做到这一点?我尝试过这样的事情:

start = message.IndexOf({ControlChars.CrLf, ControlChars.CrLf})

但返回-1。

另外,有没有更好的方法从字节数组中去除字节,我有这个:

Dim text(message.Length - start) As Byte
Dim position As Integer = 0
For i As Integer = start To message.Length - 1
    text(position) = message(i)
    position = position + 1
Next

0 个答案:

没有答案