How to remove last character from the string in ASP.NET

If you want to remove last character from the string, you can use Remove method of the StringBuilder class.
In this method, you must specify the length of the string also specify how many character remove from the string. Lets take an example , we take a StringBuilder class object, append this object with some text. After assigning some string value into object, you can remove characters from the string object.
<form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Click"
            Width="80px" />
    <asp:Label ID="Label1" runat="server" BackColor="#FFFF66" Text="Label"></asp:Label>

Code behind code-

 protected void Button1_Click(object sender, EventArgs e)
        StringBuilder stringA = new StringBuilder();
        stringA.Append("it is a text. ");
        stringA.Append("it is another text.");

        Label1.Text = stringA.ToString();

        stringA.Remove(stringA.Length - 1, 1);

        Label1.Text += "<br /><br />after removing last character from stringbuilder....<br />";
        Label1.Text += stringA.ToString();



Popular posts from this blog

difference between structure and union in C Language

Difference between Linear search and Binary Search in c language

Difference between static and dynamic websites