ContainsAny
Checks if a given string contains any of the characters in the passed array of characters.
Source
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.");
}