Mike Roosa Mike Roosa - 5 days ago 5
C# Question

How do I capitalize first letter of first name and last name in C#?

Is there an easy way to capitalize the first letter of a string and lower the rest of it? Is there a built in method or do I need to make my own?

Answer

Use System.Globalization.TextInfo.ToTitleCase(), which capitalizes every word in the string:

string text = "john doe";
string result = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text);
// Produces "John Doe"

See also MSDN Link for a detailed description.

Comments