Naive String Search Algorithm
Naive String Search is string searching algorithm. It is a simple but inefficient way to see where one string occurs inside another is to check each place it could be, one by one, to see if it's there.
Public Shared Function SearchString(str As String, pat As String) As Integer()
Dim retVal As New List(Of Integer)()
Dim M As Integer = pat.Length
Dim N As Integer = str.Length
For i As Integer = 0 To N - M
Dim j As Integer
For j = 0 To M - 1
If str(i + j) <> pat(j) Then
Exit For
End If
Next
If j = M Then
retVal.Add(i)
End If
Next
Return retVal.ToArray()
End Function
Example
Dim data = "the quick brown fox jumps over the lazy dog"
Dim value = SearchString(data, "the")
Output
0
31