In this asp .net tutorial we will learn how to convert string into upper case, lower case and to title case.we will use inbuilt .net methods to convert the string to lower, upper and title case.
Step1: Create a new asp .net website.
Step2: Add following HTML Code to your default.aspx page.
This HTML Code will create following output:
Convert String To Lower:
Write following code to button "btnToLower" click event. This code will convert string to lower case.
//==== BtnToLower to convert entered text to lower case
protected void btnToLower_Click(object sender, EventArgs e)
{
string txt = txtTextToConvert.Text.Trim();
lblResult.Text = txt.ToLower();
}
Convert String To Upper:
Write following code to button "btnToUpper" click event. This code will convert string to lower case.
//==== BtnUpper to convert entered text to Upper case
protected void btnToUpper_Click(object sender, EventArgs e)
{
string txt = txtTextToConvert.Text.Trim();
lblResult.Text = txt.ToUpper();
}
Convert String To Title:
Add Following Namespaces:
using System.Globalization;
using System.Threading;
Write following code to button "btnToProper" click event. This code will convert string to lower case.
//==== BtnProper to convert entered text to proper case
protected void btnToProper_Click(object sender, EventArgs e)
{
string txt = txtTextToConvert.Text.Trim();
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
TextInfo ti = cultureInfo.TextInfo;
lblResult.Text = ti.ToTitleCase(txt);
}
Final Output: