ToLower-ToUpper and the CurrentCulture.CultureInfo ToLower-ToUpper and the CurrentCulture.CultureInfo

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 (like when using convert date with C#).

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!

Published on Aug 8, 2011

Tags: ASP.NET MVC and Web API Tutorial | ToLower | ToUpper

Related Posts

Did you enjoy this article? If you did here are some more articles that I thought you will enjoy as they are very similar to the article that you just finished reading.

Tutorials

Learn how to code in HTML, CSS, JavaScript, Python, Ruby, PHP, Java, C#, SQL, and more.

No matter the programming language you're looking to learn, I've hopefully compiled an incredible set of tutorials for you to learn; whether you are beginner or an expert, there is something for everyone to learn. Each topic I go in-depth and provide many examples throughout. I can't wait for you to dig in and improve your skillset with any of the tutorials below.