How can you compare against multiple possibilities in one argument?
Example:
if ((integer == 2) || (integer == 5))
if ((string == \"hello\") || (str
If your integers are nonzero and small enough to fit in unsigned char
or wchar_t
, a convenient way to do this is something like:
if (strchr("\2\5", integer)) ...
or:
if (wcschr(L"\2\5", integer)) ...
Keep in mind those are octal values, not decimal. You could use hex (\x
) if you prefer.
For strings, the way to make it efficient is to use a regular expression, or write your own DFA to accept the set of strings you want to test for.