Naveen Naveen - 10 months ago 73
C# Question

Converting string to title case

I have a string which contains a mixture of upper and lower case characters, for example "a Simple string" . What I want to do is to convert first character of each word ( I can assume that words are separated by spaces) into upper case. So I want the result as "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.


MSDN : TextInfo.ToTitleCase

string title = "war and peace";

TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
title = textInfo.ToTitleCase(title); //War And Peace