get the first letter of a 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: get first number in string C#
var input = "12985bwevgjb9812";
string firstDigit = new String(input.TakeWhile(Char.IsDigit).ToArray());