I need to compare 2 strings in C# and treat accented letters the same as non-accented letters. For example:
string s1 = 'hello'; string s2 = 'héllo'; s1.Equals(s2, StringComparison.InvariantCultureIgnoreCase); s1.Equals(s2, StringComparison.OrdinalIgnoreCase);
These 2 strings need to be the same (as far as my application is concerned), but both of these statements evaluate to false. Is there a way in C# to do this?
FWIW, knightfor’s answer below (as of this writing) should be the accepted answer.
Here’s a function that strips diacritics from a string:
More details on MichKap’s blog (RIP…).
The principle is that is it turns ‘é’ into 2 successive chars ‘e’, acute. It then iterates through the chars and skips the diacritics.
"héllo" becomes "he<acute>llo", which in turn becomes "hello".
Note: Here’s a more compact .NET4+ friendly version of the same function: