Converting string to title case
c#, string
Solution
MSDN : TextInfo.ToTitleCase
Make sure that you include: `using System.Globalization`
string title = "war and peace";
TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
title = textInfo.ToTitleCase(title);
Console.WriteLine(title) ; //War And Peace
//When text is ALL UPPERCASE...
title = "WAR AND PEACE" ;
title = textInfo.ToTitleCase(title);
Console.WriteLine(title) ; //WAR AND PEACE
//You need to call ToLower to make it work
title = textInfo.ToTitleCase(title.ToLower());
Console.WriteLine(title) ; //War And Peace
Problem
I have a string which contains words in a mixture of upper and lower case characters. For example: `string myData = "a Simple string";` I need to convert the first character of each word (separated by spaces) into upper case. So I want the result as: `string myData ="A Simple String";` Is there any easy way to do this? I don't want to split the string and do the conversion (that will be my last resort). Also, it is guaranteed that the strings are in English.