-->

Saturday, April 12, 2014

How to insert string at specified position of existing string in ASP.NET

How to insert string at specified position of existing string in ASP.NET

If you want to insert another string at 0 index of existing string, suppose you have a string like "jacob" and you want to insert another string like "hello" at 0 index , then you must use insert method of the StringBuilder class with 0 index.

<form id="form1" runat="server">
    <div>
 
        <asp:Button ID="Button1"
         runat="server"
          Height="29px"
          onclick="Button1_Click"
            Text="Button"
             Width="87px" />
 
    </div>
    <asp:Label ID="Label1"
     runat="server"
      BackColor="Yellow"
      Text="Label"></asp:Label>
    </form>

CodeBhindcode-

 protected void Button1_Click(object sender, EventArgs e)
    {
        System.Text.StringBuilder stringA = new System.Text.StringBuilder();
        stringA.Append("2nd string.");

        stringA.Insert(0, "include string in front of stringbuilder. ");

        Label1.Text = stringA.ToString();

    }

Output-

How to insert string at specified position of existing string in ASP.NET

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved