Android Code Snippet Find if there is a word in a text

Subname: FindWorldInText

Description: Find if there is a word in a text. Returns True or False.

Dependencies/Libraries: None.


B4X:
Sub FindWordInText (word As String, txt As String) As Boolean
    Dim matcher1 As Matcher

    matcher1 = Regex.Matcher(word, txt)
    If matcher1.find = True Then
        Return True
    Else
        Return False
    End If
End Sub

Example:
B4X:
Log(FindWordInText("is", "This is a message"))    'Return True
Log(FindWordInText("im", "This is a message"))    'Return False
 
Last edited:
Top