Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Word search

Word search

Scheduled Pinned Locked Moved .NET (Core and Framework)
regexhelpquestion
2 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Emmery Chrisco
    wrote on last edited by
    #1

    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!

    Amerigo

    M 1 Reply Last reply
    0
    • E Emmery Chrisco

      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!

      Amerigo

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      You should check the next character for a space, period or line terminator to determine the length of the word.

      Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups