C#, Converting string into "Title Case"
Here is a nice a simple way I found to make a string "Title Case". What this means is that every word in a string will have it's first letter upper cased.
So, Here are the steps to accomplish this simple task:
1. Add using System.Globalization; to your code.
2. Create a TextInfo object. It has a ToTitleCase function we shall soon use.
TextInfo info = CultureInfo.CurrentCulture.TextInfo;
3. Convert the string you need to "Title Case".
Here is a simple sample:
static void Main(string[] args)
{
TextInfo oInfo = CultureInfo.CurrentCulture.TextInfo;
string sample = "the Is a nice way Of converting a STRing intO a title Case";
Console.WriteLine(oInfo.ToTitleCase(sample));
}
And the result will be: The Is A Nice Way Of Converting A String Into A Title Case.
Enjoy.