在html中找到body标记结束的最佳方法

Cra*_*893 2 .net html c# indexof winforms

我正在编写一个程序来为html文件添加一些代码

我打算使用一系列indexof和循环来找到本质上是"X"(其中X是我正在寻找的地方)

在我看来,可能有一种更有说服力的方式来做到这一点

有没有人有什么建议.

它目前的样子

<body onLoad="JavaScript:top.document.title='Abraham L Barbrow'; if (self == parent) document.getElementById('divFrameset').style.display='block';">
Run Code Online (Sandbox Code Playgroud)

我完成后应该是什么样子


<body onLoad="JavaScript:top.document.title='Abraham L Barbrow'; if (self == parent) document.getElementById('divFrameset').style.display='block';">
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-9xxxxxx-1");
pageTracker._trackPageview();
} catch(err) {}</script>
Run Code Online (Sandbox Code Playgroud)

mar*_*son 5

我不确定我是否理解你,但你的意思是这个吗?

// Given an HTML document in "htmlDocument", and new content in "newContent"
string newHtmlDocument = htmlDocument.Replace("</body>", newContent+"</body>");
Run Code Online (Sandbox Code Playgroud)

而且很明显我不知道c#...你可能想通过regexp使"body"标签不区分大小写.