Wednesday, October 21, 2009

How to get string in Title case

Here is the code example for converting the string to title case.

//initialize the datetime object with today's date
DateTime todaysDate = DateTime.Now;

//get the current culture
CultureInfo properCase = System.Threading.Thread.CurrentThread.CurrentCulture;

//get text info object from the current culture
TextInfo textInfoObject = properCase.TextInfo;

//the textinfo ToTitleCase method will return the text in title case
MessageBox.Show(textInfoObject.ToTitleCase(todaysDate.ToString("MMMM")));



Output:

October

Here, the todaysDate.ToString("MMMM") prints the complete month like October, December etc.

No comments:

Post a Comment