Mike Roosa Mike Roosa - 1 year ago 153
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download