Search

Saturday, April 12, 2014
0 comments

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

11:28 PMSaturday, April 12, 2014
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

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top