Steve Steve - 4 days ago 6
C# Question

How to Capitalize names

so basically if i want to transform a name from

stephen smith


to

Stephen Smith


i can easily do it with come css on the page but ideally I would like to catch it earlier on and change it when it comes out of the database. how can i get csharp to captialize a string.

is there a function for this?

Answer

You can do this using the ToTitleCase method of the System.Globalization.TextInfo class:

CultureInfo cultureInfo   = Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = cultureInfo.TextInfo;

Console.WriteLine(textInfo.ToTitleCase(title));
Console.WriteLine(textInfo.ToLower(title));
Console.WriteLine(textInfo.ToUpper(title));
Comments