ContainsAny

public static bool ContainsAny(this string theString, char[] characters)
{
	foreach(char character in characters)
	{
		if (theString.Contains(character.ToString()))
		{
			return true;
		}
	}
	return false;
}
Example:
char[] invalidFileNameCharacters = Path.GetInvalidFileNameChars();

if (newFileName.ContainsAny(invalidFileNameCharacters))
{
	MessageBox.Show("File name contains invalid characters.");
}

Description

Checks if a given string contains any of the characters in the passed array of characters.

Details

Double click on the code to select all.

 

;