views:

386

answers:

2

I was about to write my own C# extension to convert a string to Proper Case (i.e. capitalize the first letter of every word), then I wondered if there's not a native C# function to do just that... is there?

+14  A: 

There is a function that capitalises the first letters of words, though you should see the remarks section as it does have some limitations which may make it unsuitable for your needs.

Greg Beech
+1  A: 
String s  = "yOu caN Use thIs"

s = System.Threading.Thread.CurrentThread
           .CurrentCulture.TextInfo.ToTitleCase(s.toLower());

The main limitation I can see with this is that it's not "true" title case. i.e. In the phrase "WaR aNd peaCe", the "and" part should be lowercase in English. This method would capitalise it though.

Jamie Dixon
Repeat of the answer
SteveC
A downvote for posting the answer a few moments after the origional? I was still writing my answer when the accepted answer was posted. !!
Jamie Dixon