Use contains function in If condition

Hi community,
I am having an Array which contain 2 values.
Arr1={“from”,“via”}
I have sample string which may or may not contains words from mentioned array.
SampleText=“Message from Bot via UiPath”

I want to check if my SampleText contains any word from Arr1.
Please suggest logic to write in If condition

Thanks

@Akshat_Sharma1

Please try this

Arr.Any(function(x) str.ToLower.Contains(x.ToLower))

Arr - is the array of string
Str - string you want to check

This will return true if atleast one word is matching

Cheers

Hi @Akshat_Sharma1

There’s the workflow that you can use directly,

StringArray.xaml (6.9 KB)

Its works thank you so much!

1 Like

It works! Thank you

One more help! Will it possible to get which item from the array matched with sampleText?

@Akshat_Sharma1

Please try this

matchesarr = Arr1.Where(function(x) str.ToLower.Contains(x.ToLower)).ToArray

Happy Automation

Cheers

1 Like

This is working fine but for my scenario only one of the item from array will match the string. The function you shared gives array as an output. Could it be possible to get just one value which got matched?

@Akshat_Sharma1

Please use this

Arr1.Where(function(x) str.ToLower.Contains(x.ToLower))(0)

The array basically contains only one if only one matched and you can access by index (0)

Hope this helps

Cheers

1 Like

Understood! Awesome this works exactly as expected.
Thank you so much

1 Like

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