vb.net 如何进行txt内容检索

2025-04-27 07:34:28
推荐回答(1个)
回答1:

Public Function BinSearch(ByRef strElement() As String, ByVal strKey As String) As Long 
        Dim lngLow As Long
        Dim lngHigh As Long
        Dim lngMiddle As Long
        lngLow = 0
        lngHigh = UBound(strElement)
        While (lngLow <= lngHigh)
            lngMiddle = (lngLow + lngHigh) / 2
            If strElement(lngMiddle) = strKey Then
                BinSearch = lngMiddle
                Exit Function
            Else
                If strElement(lngMiddle) > strKey Then
                    lngHigh = lngMiddle - 1
                Else
                    lngLow = lngMiddle + 1
                End If
            End If
        End While
        BinSearch = -1  '查找失败
    End Function