I need to search for matching string in word document and extract whole sentence

There is a string variable, strVar which stores " public Authorities"
There is a word text file which has data below :

Cancellation Clause 30 Days (Not Applicable For Premium Payment Warranty)
Authorities Clause - Limit 10% of claim amount subject to maximum of AED 100,000/- per occurrence
Removal of Debris Clause - 10% of the admissible claim amount, maximum AED. 250,000/- any one occurrence]
Automatic Reinstatement of Sum Insured Clause - subject to pro-rata Additional Premium

I need to search for strVar which has 2 words, either of the words matching sentence in the above text file should return the whole sentence.
strVar = Public Authorities

Output Should be Authorities Clause - Limit 10% of claim amount subject to maximum of AED 100,000/- per occurrence

Anyone please help me with this…
Thanks in advance,


You can first read whole of the data using read text activity then split the data with newline and then loop through each line and then check if the line contains any of the words you need

Str.Split({Environment.NewLine,Stringsplitoptions.None) this gives array of lines

Now use loop on this array and then use if condition to check if required words are present
Strwords.Split({" "},Stringsplitoptions.RemoveEmptyEntires).Any(function(x) currentitem.ToLower.Contains(x.ToLower))

This returns true if word contains then you can save sentence else dont save


Hi @praveena.nadi

Drag and drop Invoke code activity and try this code-

Imports System.Text.RegularExpressions

Dim strVar As String = “public Authorities”
Dim fileContent As String = File.ReadAllText(“path_to_your_text_file.txt”)

Dim sentences As MatchCollection = Regex.Matches(fileContent, “([^.!?]+(?=.|!|?))”)

For Each sentenceMatch As Match In sentences
Dim sentence As String = sentenceMatch.Value
Dim words As String() = strVar.Split(" "c)

Dim containsAllWords As Boolean = True
For Each word As String In words
    If Not sentence.Contains(word, StringComparison.OrdinalIgnoreCase) Then
        containsAllWords = False
        Exit For
    End If

If containsAllWords Then
    Output = sentence
    Exit For
End If



This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.