A1VBCode Forums

Word search


http://www.a1vbcode.com/vbforums/Topic33178.aspx

By Amerigo - 9/15/2020

My program is going through each word in a story looking for names. I am using the following function to check against a string full of names (aaron, adam, ...) to see if the word is a name, but it is returning true for partial word matches such as "the" in "Theodore". What am I doing wrong?

Public Function WordExists(ByVal searchString As String, ByVal findString As String) As Boolean
    Dim returnValue As Boolean = False  
 If System.Text.RegularExpressions.Regex.Matches(searchString, "\b" & findString & "\b").Count > 0 Then returnValue = True  
 Return returnValue 
End Function


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 If WordExists(NameList, TextBox2.Text) = True
Then    MsgBox("Yep!")  
 Else    MsgBox("Nope!")  
 End If 
End Sub

Thank you for your help!