The nature of OrdinalIgnoreCase vs. intuitive expectations

by Michael S. Kaplan, published on 2007/04/25 11:39 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2007/04/25/2273289.aspx


A while back Patrick asked me:

Hi Michael,

Please forward if you’re not the right person to ask the question…

Let’s say I have the following code snippet.


int comparison = String.Compare( x, y, StringComparison.CurrentCultureIgnoreCase);
if (comparison == 0) {
      comparison = String.Compare( x, y, StringComparison.OrdinalIgnoreCase);
}


If you compare “A” and “a”, the compared results are the same (i.e. comparison=0 NO MATTER if you use current culture or OrdinalIgnoreCase). If you passed in the Turkish I (i.e. "I" and "ı" ), the first comparison result is 0 (using current culture ignore case). Since it’s 0, the code does further comparison and the value is -232 (using ordinalIgoreCase).

Since Turkish "I" and "ı", are just upper/lower case, should the 2nd comparison return 0 as well?

Thanks!
Patrick

Well, Patrick is right about the way casing in Turkic works (ref: The [Upper]Case of the Turkish İ (or: Casing, the 2nd)).

But one of the core ideas in both Ordinal and OrdinalIgnoreCase comparisons is that they stay independent of culture-specific differences, so the casing operation is independent of culture.

(Starting in .NET 2.0, the casing for OrdinalIgnoreCase even uses the operating system tables, which means on Vista it even uses the tables that were updated (first to 4.1 and then to 5.0!)

But it actually shows how weird OrdinalIgnoreCase really is, doesn't it? I mean, Ordinal is bad enough in its current form, add in casing and then all bets are off.

Just think of the operation as quite Некультурные....

 

This post brought to you by İ (U+0130, a.k.a. LATIN CAPITAL LETTER I WITH DOT ABOVE)


no comments

referenced by

2007/10/08 The roadꂸ to the solution starts with identifying the actual problem.NET

go to newer or older post, or back to index or month or day