The nature of OrdinalIgnoreCase vs. intuitive expectations

Sorting it all Out
Michael Kaplan's random stuff of dubious value
Be sure to read the disclaimer here first!

The nature of OrdinalIgnoreCase vs. intuitive expectations

  • Comments 1

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)

Comment on the blather
Leave a Comment
  • Please add 2 and 8 and type the answer here:
  • Post
Blog - Comment List
  • JJ's question was simple enough: Hello, This is probably not the right alias for this, but... I have

Page 1 of 1 (1 items)