List.Any() returning true even if search string not exist

Hi All,

I am beginner in Uipath. Iam trying to use List.Any() method to find any one of the values from list matches my search string of an excel column. My syntax looks like below,

If (DefaultList.Any(function(x) Row("Column Name).ToString.Contains(x)) )

Even if DefaultList didn’t have the if condition passes and moves to the true sequence.

Kindly assist me as I dont know what iam missing here.

Hi, can you share the workflow so we can take a look? If not possible, can you give an example of what DefaultList and the Column look like? It might be that your list contains an empty string / white space or some other thing you maybe missed.

DefaultList = [“LIB1”,“LIB2”,“LIB3”]
In excel sheet the column - Column name has the value like:
CPYFILE FROMFILE(“LIB1”) TOFILE(“LIB2”)
Since the above command got “LIB2” in TOFILE part of the string we need to consider this column cell for next porcessing.

Take a look at this and let me know if what you were trying to achieve is something like that.
example.zip (999.9 KB)

I don’t have a solution for you, but I can tell you that in my attempts to use Any() it didn’t work for me, either. I think something is wrong with it.

Thank you so much for your exmaple!

I know what’s going on and I need your thoughts on that. When im using Contains keyword on List.Any() “alike” libraries from DefaultList are matching.

Ex: DefaultList = [“LIB1”] ; Column Cell value = “LIB1@”

Here library match and pass the condition as they are alike

What should I do? Will .Equal fixes my scenario for exact match?

Try changing the if condition to this:
DefaultList.Any(Function (x) Regex.IsMatch(Row(“TargetColumn”).ToString, “\b(” + x + “)\b”))