devxlogo

InstrWord – Search a whole word

InstrWord – Search a whole word

' Return the next occurrence of a whole wordFunction InstrWord(start, Text, search, compareMethod) As Long    Dim index As Long    Dim charcode As Integer        ' assume the search fails    InstrWord = 0    index = start - 1        Do        ' search the next occurrence, exit if not found        index = InStr(index + 1, Text, search, compareMethod)        If index = 0 Then Exit Function                ' check that it is preceded by a punctuation symbol        If index > 1 Then            charcode = Asc(UCase$(Mid$(Text, index - 1, 1)))        Else            charcode = 32        End If        If charcode < 65 Or charcode > 90 Then            ' check that it is followed by a punctuation symbol            charcode = Asc(UCase$(Mid$(Text, index + Len(search), 1)) & " ")            If charcode < 65 Or charcode > 90 Then                InstrWord = index                Exit Function            End If        End If    LoopEnd Function

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist