Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6843807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:17:49+00:00 2026-05-27T00:17:49+00:00

I have the following HTML in a string variable myHtml .The myHTML variable is

  • 0

I have the following HTML in a string variable myHtml.The myHTML variable is filled with HTML from some function which return the HTML as follows

string myHtml="<table> <tr id='12345'><td>Hello1</td></tr> <tr id='12346'><td>Hello2</td></tr> </table>";

In this example, there are two rows in my returned data, and I need to add another row between the above rows with id=1234678. So then myHtml might look like

myHtml="<table> <tr id='12345'><td>Hello1</td></tr> <tr id='1234678'><td>Hello New</td></tr>  <tr id='12346'><td>Hello2</td></tr> </table>";

I want to do it by appending the HTML with the help of string operations such as indexOf, etc, but I can not figure out how to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:17:49+00:00Added an answer on May 27, 2026 at 12:17 am

    Are there always only 2 rows? If so, this will work:

    string newRow = " <tr id='1234678'><td>Hello New</td></tr> ";
    int i = myHtml.IndexOf("</tr>") + 5;            
    string newHtml = myHtml.Insert(i, newRow);
    

    If there could by any number of rows, we’ll need to write a method to find the specific index to insert at.

    e.g:

        int IndexOfNth(string source, string token, int nTh)
        {
            int index = source.IndexOf(token);
    
            if (index != -1)
            {
                int i = 1;
                while (i++ < nTh)
                    index = source.IndexOf(token, index + 1);
            }
    
            return index;
        }
    

    Then you would use:

    int i = IndexOfNth(myHtml, "</tr>", 1) + 5; // find first "</tr>" and insert after
    
    // Or you could use
    int i = IndexOfNth(myHtml, "<tr ", 2); // find second "<tr " and insert before
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am extracting some text from html which is passed as a string. The
I have a string variable that contains the following html data: <p> <em><strong>This is
I have the following variable which contains the following string. I would like to
I have the following: string html_string = http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=pharma; string html; html = new WebClient().DownloadString(html_string);
I have the following line of code. <%= Html.Encode(string.Join(, , item.company1.companies.Select(x => x.company_name).ToArray())) %>
I have a variable which will contain a relative URL (i.e. ../test.html) and I
I have a string which contains text and some <a> tags in it; I
I have a Big html in String variable and I want to get contents
I have a string variable that contains an HTML page's response. It contains hundreds
I have drawn up the following PHP code which processes the data from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.