Check if a string contains one of 10 characters

The following would be the simplest method, in my view:

var match = str.IndexOfAny(new char[] { '*', '&', '#' }) != -1

Or in a possibly easier to read form:

var match = str.IndexOfAny("*&#".ToCharArray()) != -1

Depending on the context and performance required, you may or may not want to cache the char array.

Leave a Comment