.Contains


#1

I’m trying to find a sentence on a screen using a wildcard, however I can’t get it to work.

E.g. on this page - https://www.uipath.com/activities-guide/hover on the “SimulateHover” paragraph

If I type in the full text, the Robot finds it

But add a wildcard, and it can’t

Am I doing something wrong?


#2

Hello,

The .Contains on string from .Net do not need wildcards.

Actually using just Contains(“SomeValue”) is the same as (“SomeValue*”).

If you want to reproduce “simulate the*”, when you text starts with that you can use : str.StartsWith(“simulate the”)

Cheers.


#3

Ahh ok.

My goal is to find text that will always start the same way, the middle bit needs to be a wildcard because it’ll be different text a with different amount of characters (sometimes 5 characters, sometimes 6 or 7), and the end will need to be a variable - e.g.
“Payment of” (wildcard) “to” variable

Is there any way to do this?


#4

Hi,

To do that rather use the ‘Matches’ activity, which accepts regular expressions.
If you just want to see if there is any match, you can simply use IsMatch Activity.
For you example it would be something like this.

Input your text block there.

Use the following as pattern.

"Payment of .{5,7} From " & strName

Create variables for the output matches (ex: regexMatches).

You can access the first one using regexMatches(0).ToString

I recommand you some further reading on Regular expression in .Net on the web if you want to go further. Very useful thing

Cheers.


#5

Hello,
You can just use what @Florent_Salendres suggested like StartsWith and EndsWith

If
str.StartsWith(“Payment of”) AND str.EndsWith(variable)

And, like he said above .Contains will be true if the text is located anywhere.

Thanks.


#6

@Florent_Salendres @ClaytonM

Hi both

Thanks for your replies, I’ll definitely read up on regular expression in .Net!

I’ve tried both methods but can’t get either to work. I’m sure it’s because I’m an idiot, but could you take a look and see what I’m doing wrong?

And…

Thank you!


#7

Hi,
What is not working about it? Are there errors or anything?
You might want to output DocumentScreen to make sure it’s the right text before you look at it.

also, the “&” I think it supposed to be a +
"Posted Client payment for (.*) to "+Surname

I could be wrong though.


#8

Just a quick comment - in VB.Net the & operator works for primitive types and strings, by implicitly calling .ToString() on the non-string primitive type:
"abcd" & someInt ->(same as)-> "abcd" + someInt.ToString()
See here for more on the operator.
Note: it’s actually recommended to use & operator for string concatenation, to indicate code intention.


#9

Good to know. For some reason I thought it gave an error when I was first learning UiPath concatenation methods.


#10

Hey

It’s writing the “No” line back rather than the “Yes” one.

I’ve outputted the DocumentScreen and it is the right text, annoyingly the line I’m looking for is the last line and shows up before the “No”


#11

Can you share the text output or of what you have from get visible text?

Thanks


#12

Hey

I can’t share all of it due to the data, but here’s what it looks like on the screen:

What it looks like when it’s on the WriteLine on UiPath:

And just for reference, the programme on UiPath:

If it matters, the RegexOption for the IsMatch is “IgnoreCase” and “Singleline”

Thanks :slight_smile:


#13

Hi,

From what i see in that case your variable “Surname” would need to be assigned to the value Mr Fake to work.
The pattern would the be :

"Posted Client payment of .{5,7} to " & Surname

Note that spaces matter in the pattern.

Cheers


#14

Ahh brilliant, thank you!

What would I have to add if the “Surname” variable was to be the “Surname” is “Mr Fake Surname”?


#15

Logically if should work out if you assign your variable to “Mr Fake Surname” and the visible text would be containing “Posted client payment of €15.55 to Mr Fake Surname”

Also in place of .{5,7}, i would include some sort of currency pattern that you should be able to find on the internet.

Cheers


#16

It could appear in different variations, such as “Mr Surname”, “Fake Surname”, “Mr F Surname”, “F Surname” etc so as Surname will be the only part of the name to always appear, I was hoping to go off that. I’ve played around with it and can’t seem to get it working.

Thanks for the tip, I’ll look now :slight_smile: