How to find if a string contains any items of an List of strings? How to find if a string contains any items of an List of strings? asp.net asp.net

How to find if a string contains any items of an List of strings?


The simplest code I could come up with would be:

var hasAny = children.Any(motherString.Contains);

If you expect each of the words to be seperated by a space then you could use this:

var hasAny = motherString.Split(new[] { ' ' }).Any(children.Contains);

If the words in motherString could be seperated by other characters, you could add them like this:

motherString.Split(new[] { ' ', ',', ':' })