ToLower-ToUpper and the CurrentCulture.CultureInfo

Published on Aug 8, 2011 by Jamie Munro

I have recently being working on my largest multi-lingual site ever - over 30 languages - in ASP.NET.  While implementing it, there have been a lot of bumps and bruises along the way.  One of the most recent one was noticing that the ToUpper and ToLower functions in ASP.NET take the CurrentCulture.CultureInfo into consideration.

As you may guess, this is both a blessing and a curse.

When I'm working with text that is to be translated, but should appear upper or lower case this makes perfect sense that the CurrentCulture.CultureInfo should be taking into account.  However, be sure you remember this later when you are doing text transformations and text comparisons on words that should NOT be translated.

At the end of the day, if you don't want the CurrentCulture.CultureInfo to be used, both functions can be easily overloaded as follows:
String.ToUpper(new CultureInfo("en"))
String.ToLower(new CultureInfo("en"))

I spent a fair bit of time tracking down why existing code was working perfectly, when suddenly as the team implemented the 8th language, something suddenly started failing.  Thank goodness for unit testing to quickly point out that there was a problem - then it was just a matter of understanding it!

Tags: ASP.NET | ToLower | ToUpper | CultureInfo

Related Posts

blog comments powered by Disqus