0

基本上我在 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
4

0 回答 0