-->

Wednesday, March 26, 2014

Append, modify or Edit string in ASP.NET C#

Append, modify or Edit string in ASP.NET C#

Introduction

"A group of characters known as string", Like "Hello World!". If you want to change in it, use StringBuilder class, which is a mutable string class. Mutable means, if you want create an object with some character value, also want to change in it further , that is possible with same object. So here we take StringBuilder class for appending string.

<form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
        Width="68px" BackColor="#FFFF66" />
    <div style="width: 88px">
 
        <asp:Label ID="Label1" runat="server" Text="Label" BackColor="#FFCC66"
            BorderColor="#CC0000"></asp:Label> 
    </div>
    </form>

Business Logic Code

protected void Button1_Click(object sender, EventArgs e)
 
        {
            StringBuilder stringd = new System.Text.StringBuilder();
            stringd.AppendLine("those are string.");
            stringd.AppendLine(" [ ");
            stringd.Append('H');
            stringd.AppendLine(" ] ");
            stringd.AppendLine("those are another string");

            Label1.Text = stringd.ToString();
        }  

Code Generate the following Output

output show Append, modify or Edit string in ASP.NET C#

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved