Wednesday 11 June 2014

How to convert a given word to pascal casing in ASP.NET ?

Today I am going to explain about how to convert a given word to pascal casing.

What is Pascal Casing?

The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized.

For example

Sachin Tendulkar

In the above example we have capitalized the first characters in the both the words Sachin and Tendulkar.

At most times the user may not show interest in typing the first letter of his name in capital when he is entering his name in a text box. At that time we need a code in the backend which can automatically convert the text to capitals.

Take an asp textbox.

<asp:TextBox Id=”txtName” runat=”server”>

Call this textbox in the aspx.cs page.

Now write the following code in the aspx.cs page to convert the first letter each subsequent concatenated word to capitals.

System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(txtName.Text.ToLower());


This code automatically converts the starting letter of each word to capitals.