ToLowerInvariant() and ToUpperInvariant()

According to business rule all footballer name and surname must be capitalized and not longer than 8 chars length.

Very simple to develop. We develop a wrapper method for this job. Seems working fine. Until this morning. Game masters of the http://icanfootball.com noticed that some player names violates this business rule. After my first debuging i found the problem. ToLowerInvariant method is the guilty. No, infact the developer who uses this method is guilty. Because this methods unable to convert “i” to “İ”, “ı” to “I” or reverse. This chars specific to Turkish locale and this methods are invariant (means Culture Indepentend and works same as calling ToLower or ToUpper method with CultureInfo.InvariantCulture enum). 

So in my opinion this methods are useless. Please use ToLower or ToUpper method with appropriate culture info.

You can check this sample code:

string a = "ı I ş Ş ç Ç ğ Ğ ö Ö ü Ü i İ";

string b = a.ToLowerInvariant();//b = "ı i ş ş ç ç ğ ğ ö ö ü ü i İ" fails to convert
string d = a.ToUpperInvariant();//c = "ı I Ş Ş Ç Ç Ğ Ğ Ö Ö Ü Ü I İ" fails to convert

string culture = "tr-TR";
System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo(culture);

string c = a.ToLower(cultureInfo);//d = "ı ı ş ş ç ç ğ ğ ö ö ü ü i i"
string e = a.ToUpper(cultureInfo);//e = "I I Ş Ş Ç Ç Ğ Ğ Ö Ö Ü Ü İ İ"

Happy coding…

Posts created 141

Leave a Reply

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top