Having trouble searching for this, but I bet there's a question about it somewhere I couldn't find. Is there a tidier way to write something like If[x=="a"||x=="b"||x=="c", blah, bloo] other than maybe Switch[x,"a"|"b"|"c",blah,_,bloo] ?
@MarkS. what exactly you do not like with `If[x=="a"||x=="b"||x=="c", blah, bloo]` ? is it that you do not want to use || so many times? I see nothing wrong with it. But one possible way is then to use AnyTrue. something like
x = "a";
test = AnyTrue[{"a", "b", "c"}, x == # &];
If[test, "yes", "no"]
Thanks for the response. What I didn't like is the repetition of x. It can also be avoided by using MemberQ, but AnyTrue is good to remember, too. Both of those are on the long side. I guess I was hoping for something like If[match[x,"a"|"b"|"c"],... for a suitable builtin match
@MarkS. There are MatchQ and StringMatchQ, but frankly I would expect MemberQ win them in some cases. These have different properties for generalised cases or performance; in addition to using Dispatch, there's compiled string pattern caching which may affect performance, and if you are applying your match on large number of items, you probably want to write it as a replacement rule and use Replace instead. So, there isn't one perfect solution that fits all scenarios...