How To Easily Convert Strings to Mixed Case (aka Title Case, aka Proper Case) in C#

I found a very easy way to convert strings to mixed case (aka Title Case, aka Proper Case) in C# today. The String class does not have a method to do this, but the TextInfo class of the System.Globalization namespace does -- the ToTitleCase() method.

An important thing to note is that it doesn't work on strings that are all upper case, so convert the string to lower case first to make it work. See the example below, where sTheStringYouWannaConvert represents the string you want to convert (go figure):
string sMixedCaseString = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(sTheStringYouWannaConvert.ToLower());

It's just that easy. :)

Comments

Popular Posts

Resolving the "n timer(s) still in the queue" Error In Angular Unit Tests

How to Get Norton Security Suite Firewall to Allow Remote Desktop Connections in Windows

How to Determine if a Column Exists in a DataReader

Silent Renew and the "login_required" Error When Using oidc-client

Fixing the "Please add a @Pipe/@Directive/@Component annotation" Error In An Angular App After Upgrading to webpack 4