Today, I ran into a situation where I needed to proper case a string for display purposes. After a little research on Google, I found a few snippets and put them together to make this extension method:
public static string ToProper(this string value)
{
return Regex.Replace(value, @"\b(\w)(\w+)?\b", new MatchEvaluator(match =>
string.Concat(match.Groups[1].Value.ToUpper(),
match.Groups[2].Value)), RegexOptions.IgnoreCase);
}
This will take a string and convert it into proper case by capitalizing the first letter of each word. Hopefully, this will help someone else out.