Follow in Twitter & Facebook


Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools


Friday, September 21, 2012

Convert first letter to uppercase in C#.Net

In this article we will discuss how can we convert first letter to upper case using C#.Net. Also you can check my last article on how to check if string contains a particular string in C#.Net here.  Also you can see a very good article on Remove HTML tags from string in C#.Net.

Below is the full code:
Html code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Convert first letter to uppercase in C#.Net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtEnterText" runat="server"></asp:TextBox><br />
        <asp:Button ID="btnTest" runat="server" 
            Text="Convert First Letter To UpperCase" onclick="btnTest_Click" /><br />
        <asp:Label ID="lblResult" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>

.cs code:
protected void btnTest_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txtEnterText.Text))
        {
            char[] allLetters = txtEnterText.Text.Trim().ToCharArray();
            allLetters[0] = char.ToUpper(allLetters[0]);
            string outPut = new string(allLetters);
            lblResult.Text = outPut;
        }
}

The output will appear like below:




0 on: "Convert first letter to uppercase in C#.Net"