How to check if last line of text file contains one word?

Dears,

How to check if last line of text file contains one word ? Thx

1 Like

We can use variablename.ToString.EndsWith(“your term”) method

Or

If that doesn’t end with text rather just be there in the last line of the text then
This expression would help you

If the text is stored in str_input
Then

str_output = str_input.Split(Environment.Newline.ToArray()).last.ToString.Contains(“your keyword”).ToString

Cheers @hsendel

1 Like

Kindly let know for any queries or clarification
Cheers @hsendel .

I tried both Methodes and didn’t work. Could you please help?CheckIfLastLineContainsWord.xaml (6.7 KB) Example.zip (384 Bytes)

Hello @hsendel
if you want to check the last word then you can use regex Ismatch method to get a boolean value and using this pattern yourword$

check this workflow if you want something like this and to understand more clearly
Ismatch.xaml (5.7 KB)

1 Like

Hello vickydas

I got the follwoing error:

for this error it’s OK : Regex is not declared

@ vickydas,

I tried your code didn’t work :crying_cat_face:Ismatch_Bis.zip (1.8 KB)

Hello @hsendel
The reason that code didnt work is its only checking the last word
i misread it
Try this code it’ll definitely work

System.Text.RegularExpression.Regex.IsMatch((System.Text.RegularExpression.Regex.Regex.Match(Your Variable,".+\z").ToString),"the desired word").ToString

Let me know about it

2 Likes

Working Perfect!!! Thanks a lot vickydas

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