Home » Programming / Coding

How to Convert String to Title Case – ASP .NET

11 August 2010 1,072 views No Comment

Often times you might need to convert input string to title case.
For example converting the string “mY GiaNT bREAkFST” to “My Giant Breakfast”

Using this simple method you could convert an input string to title case

public class Converter
{
public static string ConvertToTitleCase(string input)
{
TextInfo ti = Thread.CurrentThread.CurrentCulture.TextInfo;
//if a word is all in upper case, ToTitleCase method is not able to convert to title case. So we would make the input string all lower case.
return ti.ToTitleCase(input.ToLower());
}
}

To use this method you can simply call the static method like this:
string str = Converter.ConvertToTitleCase(“mY GiaNT bREAkFST”)

From Webcosmo Webmaster Forum http://www.webcosmoforums.com/asp/21519-how-convert-string-title-case-asp-net.html

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.