I want to find whether a string contains any of the special characters like !,@,#,$,%,^,&,*,(,)....etc.
How can I do that without looping thorugh all the charact
public static bool HasSpecialCharacters(string str)
{
string specialCharacters = @"%!@#$%^&*()?/>.<,:;'\|}]{[_~`+=-" +"\"";
char[] specialCharactersArray = specialCharacters.ToCharArray();
int index = str.IndexOfAny(specialCharactersArray);
//index == -1 no special characters
if (index == -1)
return false;
else
return true;
}