Proper Casing a String in .NET

by bob on December 27, 2006

Rick Strahl saved me a minor headache today by pointing out a somewhat hidden and arguably misplaced method in the BCL for proper casing strings. Combining that with a small fix provided by one of his respondents (the method doesn’t work if the input string is all upper cased), you get:

private string ProperCase(string s) {
  return System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(s.ToLower());
}

As he aptly points out, it’s all there somewhere in the dogpile, if only you can find it.

Leave a Comment

Previous post:

Next post: