Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB4,VB5,VB6,VBS
Expertise: Intermediate
Feb 26, 2000

InstrWord - Search a whole word

' Return the next occurrence of a whole word

Function 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
    Loop

End Function
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date