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):
It's just that easy. :)
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
Post a Comment