Lowry Media
Extension Methods - ToProper (Proper case)
May 28, 2008 5:19 PM
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.
Return to Previous Page
Comments
Comment posted on Jul 28, 2008 5:06 AM
Naz
Hi, Here's a alternative way you can do it.

public static string ToTitleCase(this string s)
{
return Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(s.ToLower());
}
Naz
Comment posted on Jul 28, 2008 1:12 PM
Brian
Wow, that's extremely helpful. Thanks for the input.
Brian
Add Comment