find capital letter in string c# 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: capitalize c#

string input = "hello!";
Console.Write(char.ToUpper(input[0]) + input.Substring(1))

//prints "Hello!"