If case conversion were harder, people would do it less

by Michael S. Kaplan, published on 2010/09/26 07:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2010/09/26/10067840.aspx


It was just last night that I got the following mail:

Hi. I have seen your blogs regarding invariant culture, collation, etc and they are very, very useful. Thanks!

Also, if you don’t mind, I do have a question :-). Do you know why the results below are different.

Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
string upper = "FILE";
string tolowerCultureSenstive = upper.ToLower();
string tolowerInvariant = upper.ToLowerInvariant();

The results will be:
tolowerCultureSenstive --> fıle
tolowerInvariant --> file

My guess is that the tr-TR is not in the default collation table?

Well, there is a little confusion here since the methods involved refer to casing yet the question is about collation.

And as I have mentioned before, Collation != Case (a.k.a. Collation <> Case).

Though for both casing and collation, Turkic languages see the specific alternate behavior with the letter "I" as I described in The [Upper]Case of the Turkish İ (or: Casing, the 2nd).

Now any time one is dealing with files and the like, one needs to use the invariant style methods because it is important to avoid differences based on configuration. Changing the answer for Turkish to questions like "does the file" exist would never be a good idea but in particular is doing the wrong thing for a few other reasons:

If one is trying to mimic in managed code checks done in native code, then doing the same types of checks/comparisons is the best way to avoid bugs and problems down the road....

Personally, I wish case conversion wasn't so easy. If it were harder to do then perhaps it would happen less since in most cases it is the wrong thing to do! :-)


no comments

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

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