我想在网页浏览器中找到字符串位置,然后如果用户想要编辑它,我可以找到带有此代码的字符串数
public int SearchEle(HtmlElement ele, string txt)
{
int Find_Num = 0;
int Location = 0;
foreach (HtmlElement child in ele.Children)
{
Find_Num += SearchEle(child, txt);
}
string innertxt = ele.InnerText;
if (!string.IsNullOrEmpty(innertxt) && innertxt.Contains(txt))
{
int Find_Num += Regex.Matches(innertxt, txt).Count;
}
return Find_Num;
}
对于搜索字符串
int find_count = SearchEle(HTMLEditor.Document.Body, word));
但是如何在web浏览器(HTMLEditor.Document.Body.InnerHtml
)的 HTML中找到查找字符串的索引?
答案 0 :(得分:0)
var index = HTMLEditor.Document.Body.InnerHtml.indexOf('你要找的字符串');