Naveen Naveen -4 years ago 192
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.

Answer Source

MSDN : TextInfo.ToTitleCase

string title = "war and peace";

TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
title = textInfo.ToTitleCase(title); //War And Peace
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download