在第n次出现令牌后插入字符串

时间:2011-11-22 16:09:10

标签: c# html string

我在字符串变量myHtml中有以下HTML。myHTML变量用某些函数填充HTML,返回HTML如下

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

在此示例中,我返回的数据中有两行,我需要在上面的行与id=1234678之间添加另一行。那么myHtml可能看起来像

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>";

我想通过在诸如indexOf等字符串操作的帮助下附加HTML来实现它,但我无法弄清楚如何执行此操作。

1 个答案:

答案 0 :(得分:5)

不要为此使用字符串,而是为此使用库。例如HTML agility pack

相关问题