How to find if a string contains a string within in

Hi All
I would like to know how to find if a String A contains String B, but there can be a change that String B has words in Jumbled order.
I know how contains method work, but whenever my String B has words in jumbled order , it returns false.
If String B has words in same order as String A, then it returns true.

Please help, what else we can use over here.

Thanks in Advance.

Ideally, you’ll want String B to be split into an array of strings and check if any of those strings are in String A. Here’s an example:

If StringA = "The quick brown fox jumped over the lazy dog.", and StringB = "fun what that over at snake", then you can follow these steps.

1.) Split StringB at spaces into variable StringBArr = StringB.Split(" ").
2.) Create a boolean called StringFound set to False at this point.
3.) Start a For Each loop over StringBArr where SubStr is an element in StringBArr.
4.) Inside the loop, add an If statement with condition StringA.Contains(SubStr).
5.) If the condition is True, set StringFound = True and then break from the loop with a Break activity.

If the no substring is found to match within StringA, StringFound will remain False as defined before the loop started. Otherwise, it will be set to True.

1 Like

It would be better if you give us an example that will suite your case more specifically…

1 Like

I have an example,
I created a string of numbers with spaces between them (like this: “1 10 19 35 36 37 38 45 46 47 61 63 64 65 66 68 90 92 93”) and I want to check if a number that I will get as an input from the client is exist in that list

myStringArray = varStringWithNumbers.Split(" ")
IF myStringArray.Contains(varNumberToCheck.ToString)
2 Likes