Click here to Skip to main content
11,706,477 members (47,572 online)
Click here to Skip to main content

Tagged as

Convert text to TitleCase

, 21 Feb 2010 CPOL 10K 1
Rate this:
Please Sign up or sign in to vote.
In C#, the System.String class contains methods ToUpper and ToLower which convert the case of the string to UPPERCASE and lowercase respectively.But the String class does not have an appropriate method to convert text to TitleCase.No need to worry, the TextInfo class provides this method! ...
In C#, the System.String class contains methods ToUpper and ToLower which convert the case of the string to UPPERCASE and lowercase respectively.
But the String class does not have an appropriate method to convert text to TitleCase.

No need to worry, the TextInfo class provides this method! Smile | :)

Here is how you achieve TitleCase:

TextInfo myTextInfo = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo;
 
string sampleStr = "this IS a sample text";
string titleStr = myTextInfo.ToTitleCase(sampleStr);
Console.WriteLine(titleStr);

The above code snippet will print the following:

This Is A Sample Text

More information regarding TextInfo can be found here.[^]

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ratish Philip
Software Developer NA
India India
Ratish Philip is a software developer with 8 years of experience. He loves programming in C#, WPF & Silverlight.

He is currently exploring the depths of Windows 8 programming.

Creating enriched user experiences is what appeals to him the most.

Occasionally expresses his creativity through pencil sketching too!

Ratish's personal blog: wpfspark.wordpress.com

You may also be interested in...

Comments and Discussions

 
QuestionComment Please Pin
dotnetpickles9-Feb-14 19:45
memberdotnetpickles9-Feb-14 19:45 
GeneralReason for my vote of 3 This is a good method for C#, or eve... Pin
yannduran23-Aug-11 18:19
memberyannduran23-Aug-11 18:19 
GeneralWhat About Silverlight? Pin
Alexeins16-Oct-10 17:55
memberAlexeins16-Oct-10 17:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150819.1 | Last Updated 21 Feb 2010
Article Copyright 2010 by Ratish Philip
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid