Seeing if text is in a document or not

Hi there,

Is there a way to see if a text file contains specific text?

Hello there! Yes!

After reading the document, you can use either YourVariable.contains(“Valuebeingsearchedfor” put it in an if condition then you are good to go :slight_smile:

or you can use regular expressions also


Thanks for your response! But is there another way to do it without using a variable? btw I am working with a word document if that makes any difference.

Hello @Evan123, to check if a document contains a keyword or a search term, you need to read that document and when you read it, you need to store it in a variable.

Now that you’ve created a variable with the contents of the word file, you can use .contains() method to search. This will return a boolean so, you can use this in an if condition or a flow decision.

You can also go with Regular Expressions as suggested by @seanrockvz13.

1 Like

Hi @Evan123, May i check why you don’t want to use any variable?

Simply because I’m not that comfortable with UIPath yet, and if I can use an activity that simply lets me select a file and see if text is in it or not that makes my life easier. Although using a variable may be the most efficient way to do it, I’m looking for the easiest.

@Evan123 - Are you looking something like this…

After installing Word Package I have tried something like below…

Note: Since I did not find Search activity, I have used Replace and replaced the same text so that the document will not be impacted.

Another Option would be using UI Automation to send HotKey/Keyboard Shortcuts to send Ctrl F and Type into the searh text you are looking for…in this way also you dont have to use any code…

Thanks for this, I’ll give those activities a shot. I actually tried using the send hotkey shortcuts, but the problem with that I ran into, is I don’t know how to give myself a sucess/failure message based of the result of the ctrlF searches…

@Evan123 - Sure…After the Ctrl F , you have to Get Text activity to read the result. in this way, you can make sure whether the searched string is found or not…


If you dont get the above text, it means the searched text is found.