Why is it so verbose to compare two strings in C# and see if they are equal, while ignoring case?
What I mean is this:
("Apples" == "apples") => falseTake the following examples, each of which does what I want it to, however
there is so much noise code here that it really takes away from the readability of the code:
Assert.That(matches[0].Email.Equals(email, StringComparison.InvariantCultureIgnoreCase));
Assert.That(matches[0].Email.ToLower().Equals(email.ToLower()));
Assert.That(string.Compare(matches[0].Email, email) == 0);
Assert.That(Regex.Match(matches[0].Email, email, RegexOptions.IgnoreCase).Success);
Each one of these works, but I really wish this was a language feature. Wouldn't it be nice to have a new operator syntax?
Assert.That(matches[0].Email ==? email);
//or
Assert.That(matches[0].Email ==~ email);
It turns out that we're not alone. Ruby and Python have the same problem, however their regular expressions option is much more elegant looking (due to the languages having regex as a core feature). This seems like such a common need that I'm surprised that this type of thing isn't built into the core of most languages.
Granted, there are concerns about how each one of these would behave, for example, how do you compare strings from two different cultures? In my case I'm always dealing with English characters, but I fully understand the need to support internationalization.
What do you think? Would you welcome a new operator to save your self some typing and improve readability?