Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

C# - Convert String (Text) to Title Case (Proper Case), Upper Case, Lower Case in Asp.net

Sep 8, 2015
Introduction

Here I will explain how to convert string or text to title case or proper case, upper case and lower case in
asp.net using c#, vb.net with example. By using system default properties we can convert text or string to upper case and lower case but to convert text to proper case or title case we need to use CultureInfo namespaces properties to convert text or string to proper case / title case in asp.net using c#, vb.net.

Description:
  
In previous articles I explained sql server convert string to proper case (title case) example, jQuery send & Receive json objects from web service in asp.net,
bind gridview using jquery json method in asp.net, show multiple markers in google map from database in asp.net and many articles relating to gridview, asp.net, c#,vb.net and jQuery. Now I will explain how to convert string / text to title case / proper case, upper case and lower case in asp.net using c#, vb.net with example.

To convert text to proper case, upper and lower case in asp.net open your aspx page and write the following code


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Convert String to Title Case (Proper Case), Upper Case, Lower Case in Asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<b>Enter Text to Change: </b> <asp:TextBox ID="txtDetails" runat="server" Text="hi, welcome to aspdotnet-suresh.com"/><br /><br />
<asp:Button ID="btnTitleCase" runat="server" Text="Title Case" onclick="btnTitleCase_Click" />
<asp:Button ID="btnLowerCase" runat="server" Text="Lower Case" onclick="btnLowerCase_Click" />
<asp:Button ID="btnUpperCase" runat="server" Text="Upper Case" onclick="btnUpperCase_Click" />
<br /><br />
<asp:Label ID="lblResult" runat="server" Font-Bold="true"></asp:Label>
</div>
</form>
</body>
</html>

After completion of aspx page add following namespaces in codebehind

C# Code


using System;
using System.Globalization;
using System.Threading;

After completion of adding namespaces you need to write the code like as shown below


protected void btnTitleCase_Click(object sender, EventArgs e)
{
CultureInfo culinfo = Thread.CurrentThread.CurrentCulture;
TextInfo txtinfo = culinfo.TextInfo;
lblResult.Text = txtinfo.ToTitleCase(txtDetails.Text);
}
protected void btnLowerCase_Click(object sender, EventArgs e)
{
lblResult.Text = txtDetails.Text.ToLower();
}
protected void btnUpperCase_Click(object sender, EventArgs e)
{
lblResult.Text = txtDetails.Text.ToUpper();
}

VB.NET Code


Imports System.Globalization
Imports System.Threading

Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Sub btnTitleCase_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim culinfo As CultureInfo = Thread.CurrentThread.CurrentCulture
Dim txtinfo As TextInfo = culinfo.TextInfo
lblResult.Text = txtinfo.ToTitleCase(txtDetails.Text)
End Sub
Protected Sub btnLowerCase_Click(ByVal sender As Object, ByVal e As EventArgs)
lblResult.Text = txtDetails.Text.ToLower()
End Sub
Protected Sub btnUpperCase_Click(ByVal sender As Object, ByVal e As EventArgs)
lblResult.Text = txtDetails.Text.ToUpper()
End Sub
End Class

Demo

Output to Convert String (Text) to Title Case (Proper Case), Upper Case, Lower Case in Asp.net


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

1 comments :

Anonymous said...

sir can you plz tell me how can i make proper case as like lower case and upper case

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.