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

2 Comments »

  1. Usefull post thank you…

    Comment by Manoj Kumar — October 16, 2012 @ 9:53 am | Reply

  2. this is camelCase
    this is PascalCase
    see:
    https://msdn.microsoft.com/en-us/library/x2dbyw72%28v=vs.71%29.aspx?f=255&MSPPError=-2147217396

    Keep it simple:
    CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text)

    Replace Spaces:
    Regex.Replace(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text), @”\s+”, string.Empty);

    Comment by Eff Ewe — March 20, 2015 @ 6:04 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: