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.
Are there always only 2 rows? If so, this will work:
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:
Then you would use: