so basically if i want to transform a name from
stephen smith
to
Stephen Smith
i can easily do it with c
This is an extension method on the string class that capitalizes a single word. You can use it alongside a str.Split()
and str.Join
to capitalize every word of the str
string. You can add checks for empty or one character length strings.
public static string Capitalize(this string word)
{
return word.Substring(0, 1).ToUpper() + word.Substring(1).ToLower();
}