Sai Stuff to Developers

October 15, 2012

Converting a String to Title Case or Camel Case in C#

Filed under: DotNet — tosaik @ 6:28 am
Tags: , , ,

Now I am going to show how we can convert a string to a Title case or we also say it as Camel Case. For example I have a string as shown here


string name = "sai kUmar";

Now I need to convert the above string to Title case or we also say it as Camel Case, for this we have a special class called TextInfo which exist in the System.Globalization namespace. This special class has a special method called ToTitleCase() and which accepts only one string parameter and we need to pass our string need to convert through this parameter as shown below..


System.Globalization.TextInfo myTI = new System.Globalization.CultureInfo("en-US", false).TextInfo;
name = myTI. ToTitleCase(name);

Output: Sai Kumar

Note: Please provide your Current Culture while initializing TextInfo class object.

Hope this will helps you…

Happy Coding 🙂

Advertisements

Create a free website or blog at WordPress.com.

%d bloggers like this: