A simple extension method that will use the first letter of a string. As Karl noted, this suggests that the first letter is correct for change and therefore not entirely safe for culture.
public static string CapitalizeFirstLetter(this String input)
{
if (string.IsNullOrEmpty(input))
return input;
return input.Substring(0, 1).ToUpper(CultureInfo.CurrentCulture) +
input.Substring(1, input.Length - 1);
}
You can also use System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase . The function converts the first character of each word to uppercase. Therefore, if your input line have fun, the result will be have fun.
public static string CapitalizeFirstLetter(this String input)
{
if (string.IsNullOrEmpty(input))
return input;
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input);
}
. .