Deal with it or don't

Obvious Extension Method: ToTitleCase for strings

Got data that’s all upper case? All lower case? Want it title case, or proper case?

  1. using System.Globalization;
  2. public static class StringExtensions
  3. {
  4.     public static string ToTitleCase(this string value)
  5.     {
  6.         var textInfo = new CultureInfo(“en-US”, false).TextInfo;
  7.         return textInfo.ToTitleCase(value.ToLower());
  8.     }
  9. }

“WHY AM I SHOUTING?”.ToTitleCase() returns “Why Am I Shouting?”

“the meek shall inherit the earth.”.ToTitleCase() returns “The Meek Shall Inherit The Earth.”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: