How to efficiently check IF string contains any string of Array

Hello friends,

I have a small question, I think the title is self explanatory but let me give you an example.

I have the following two strings:
“Invoice 1230258”
“Project 1230258”
and the following array of strings: Invoice, Order, etc, etc

If the string contains any of the strings in the array I want a boolean to be true.
So for the first string the output will be true. For the second string the output would be false.

Use loop here.

For each value in ARRAY
set Boolean to true

You can create reusable xaml and pass the strVariable


Check the array contains the string,

YourArray.Contains("yourString".Split(" "c, stringsplitoption.none))

I dont think this will work since the array doesnt contain the numbers in the string. So the boolean will always be false

Hmm, I see what you did there. Actually kind of easy. Thanks!

1 Like

Cheers Mate!

That’s why I am splitting the string and using the first part alone, so here Invoice alone will be checked in that array.

1 Like

Alright! I understand now. I dont think it will be usable in my case because the case is slightly more complex than the example I used. But thanks anyways! I think I can use this later in my process!

1 Like

More efficient that For Each loop I guess:

values = string() {"Invoice", "Order", "etc."}
text = "Invoice 12345678"
isFound = values.Any(function(x) text.Contains(x))



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