c sharp first letter uppercase code example

Example 1: c# capitalize first letter

string text = "john smith";

// "John smith"
string firstLetterOfString = text.Substring(0, 1).ToUpper() + text.Substring(1);

// "John Smith"
// Requires Linq! using System.Linq;
string firstLetterOfEachWord =
		string.Join(" ", text.Split(' ').ToList()
				.ConvertAll(word =>
						word.Substring(0, 1).ToUpper() + word.Substring(1)
				)
		);

Example 2: c# string capitalize first letter of each word

//Try TextInfo.ToTitleCase(String) Method
System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase("your text");