ContainsAny

public static bool ContainsAny(this string str, params string[] values)
        {
            if (!string.IsNullOrEmpty(str) || values.Length == 0)
            {
                foreach (string value in values)
                {
                    if(str.Contains(value))
                        return true;
                }
            }

            return false;
        }
Example:
string testString = "Hello world.  This is a test";

bool result = testString.ContainsAny("Hello", "test");

Description

Returns if a given string contains any of the characters provided in a params array of strings.

Details

Double click on the code to select all.

 

;