Search

Wednesday, March 26, 2014
0 comments

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

5:29 AMWednesday, March 26, 2014

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#
Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top