There is no direct string function to convert a given case string to a Mixed Case or Title Case (first letter of the word is capitalized)
Below is the code you can achieve this using the CultureInfo in Globalization namespace:
string myString = "test string";
System.Globalization.CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Globalization.TextInfo textInfo = cultureInfo.TextInfo;
string mixedCaseString = textInfo.ToTitleCase(myString.ToLower());
The mixedCaseString will be "Test String".
Convert a given string to Mixed Case or Title Case
Posted by Techie Cocktail | 5:51 PM | C-Sharp | 3 comments »
Subscribe to:
Post Comments (Atom)
Well written article.
Thanks - your article was just what I needed, consise and to the point.
One additional item I wish to point out, you may want to change myString to myString.ToLower() when you pass it to "ToTitleCase".
I have found the it will not DROP the case of letters... for instance..
"MY STRING" will remain as "MY STRING" - the function appears to only "look at" the first character of each word.
Thanks again!
Chris
Thanks for the catch Chris. I have updated the code.