Peter Petrov’s Weblog

var me = from practice in programming where practice.IsBestPractice && practice.UseLambda select practice.OptimalPerformance;

Useful method – 8 of N – String Capitalize First (ToTitleCase) June 30, 2008

I’ve wanted to rename a lots of files. I’ve also wanted the name of the files to follow my convention to capitalize every first letter. I couldn’t find such functionality in the string class. I’ve googled and I’ve found the TextInfo class and ToTitleCase method. It gets the job done and perfectly suits me needs.

Here’s how we can use it

TextInfo ti = Thread.CurrentThread.CurrentCulture.TextInfo;
string name = "petar petrov - XML developer";
string properName = ti.ToTitleCase(name);
// properName = "Petar Petrov - XML Developer"

Note that the XML isn’t transformed to Xml which is the correct behavior for me.


One Response to “Useful method – 8 of N – String Capitalize First (ToTitleCase)”

  1. Elijah Manor Says:

    Ahh that looks like a very useful class. I wonder if it changes its behavior based on the culture?

    BTW, good job with your riddle guesses šŸ™‚

    I will post a new one today.

Leave a Reply

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

You are commenting using your 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