ArrayIndexOf – An extended version of Array.IndexOf

ArrayIndexOf – An extended version of Array.IndexOf

' An extended version of Array.IndexOf, with more options for string searches. ' The function returns the index of the found element,'  or -1 if no element is found'' Example:'   Dim arr As String() = {"this is a string for my test", "test number 2",'  "another String", "do you like this string?", "I like running tests"}'   Dim i As Integer = -1'   Do'       i = ArrayIndexOf(arr, "string", i + 1, False, False)'       If i > -1 Then'           Debug.WriteLine(arr(i))'       End If'   Loop While i > -1Function ArrayIndexOf(ByVal arr As String(), ByVal search As String) As Integer    Return ArrayIndexOf(arr, search, arr.GetLowerBound(0))End Function' this overloaded version allows you to specify also the array's index to start ' fromFunction ArrayIndexOf(ByVal arr As String(), ByVal search As String, _    ByVal startIndex As Integer) As Integer    Return ArrayIndexOf(arr, search, startIndex, True)End Function' this overloaded version allows you to specify also whether the search is case-' sensitiveFunction ArrayIndexOf(ByVal arr As String(), ByVal search As String, _    ByVal startIndex As Integer, ByVal caseSensitive As Boolean) As Integer    Return ArrayIndexOf(arr, search, startIndex, caseSensitive, True)End Function' this overloaded version allows you to specify also whether only exact matches ' are validFunction ArrayIndexOf(ByVal arr As String(), ByVal search As String, _    ByVal startIndex As Integer, ByVal caseSensitive As Boolean, _    ByVal exactMatch As Boolean) As Integer    ' if the search is case-sensitive and it runs against exact matches only,    '  use the standard Array.IndexOf function    If caseSensitive And exactMatch Then        Return Array.IndexOf(arr, search, startIndex)    End If    If Not caseSensitive Then search = search.ToLower()    Dim lastIndex As Integer = arr.GetUpperBound(0)    Dim i As Integer    For i = startIndex To lastIndex        Dim currElem As String = arr(i)        ' if the search is not case-sensitive, convert everything to lower-case        If Not caseSensitive Then currElem = currElem.ToLower()        If exactMatch Then            If search = currElem Then Return i        Else            ' if partial matches are ok, use the String.IndexOf function,            '  and return the            ' current index if a partial match is found            Dim j As Integer = currElem.IndexOf(search)            If j > -1 Then Return i        End If    Next    ' if we get here, no element matches the search options, so return -1    Return -1End Function

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several