capitalize first letter of each word in string c# code example
Example 1: c# capitalize first letter
string text = "john smith";
string firstLetterOfString = text.Substring(0, 1).ToUpper() + text.Substring(1);
string firstLetterOfEachWord =
string.Join(" ", text.Split(' ').ToList()
.ConvertAll(word =>
word.Substring(0, 1).ToUpper() + word.Substring(1)
)
);
Example 2: c# capitalize first letter of each word in a string
string s = "THIS IS MY TEXT RIGHT NOW";
s = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(s.ToLower());
Example 3: c# make first letter uppercase
System.Console.WriteLine(char.ToUpper(str[0]) + str.Substring(1));