Is there an opposite of IndexOf()? Perhaps NotIndexOf()?
c#
Solution
Or use LINQ:
if (myStr.Any(c => c != '0' && c != '1'))
....
Problem
If myStr is supposed to contain 0's and 1's, how can I search this string for anything that is not a 0 or 1? For example: ``` string myStr = "1001g101"; if (myStr.IndexOf(NOT "0") != -1 && myStr.IndexOf(NOT "1") != -1) { Console.Write("String contains something that isn't 0 or 1!"); } ``` My reason for doing this is not wanting to do a full ASCII character map and have it check each character against all ASCII characters, it seems way too inefficient. If I have to check each character and ensure 0 or 1, that will work, but is there a better way? I am not good with Regex, but I suspect that may hold my answer.