Does a culture like StringComparison String.Equals affect?

In C #, you can compare two strings with String.Equals and put StringComparison .

I recently tried to update my archaic ToLower() comparison method, because I read that it does not work in all languages ​​/ cultures.

From what I can tell, comparison types are used to determine the order when I come across a list containing aƩ and ae , which should be displayed first (some cultures arrange things differently).

With String.Equals ordering doesn't matter. Therefore, is it possible to assume that many of the options are irrelevant, and only the [Ordinal] and [Ordinal] IgnoreCase are important?

MSDN article for String.Equals says

The compareType parameter specifies whether the comparison should use the current or invariant culture, to honor or ignore the case of comparing two lines, or to use the rules for sorting by word or ordinal order.

string.Equals(myString, theirString, StringComparison.OrdinalIgnoreCase)

I am also interested to know how the sorting method works internally, does it String.Compare to determine the relative position of two strings?

+7
source share
1 answer

Case insensitive comparisons are culture dependent. For example, using Turkish culture, i not a lowercase letter for i . With this culture, i mates with ı , and ı mates with i . See Dotted and Countless I on Wikipedia .

There are a number of strange effects related to culture-sensitive string operations. For example, "KonNy".StartsWith("Kon") may return false .

Therefore, I recommend switching to culture-insensitive operations, even for seemingly harmless operations.


And even with culture-insensitive operations in Unicode, there are many unintuitive actions, such as multiple representations of the same glyph, different code points that look the same, zero-width characters that some operations are ignored but observed by others ...

+7
source

All Articles