加入对象(HTML集合)内部字符串的最佳方法?使用Microsoft Studio 2008中,NET 3.5,与HTMLagilityPack对象内部加入字符串的最佳方法
这里的HTML
<div class="content">
<ul>
<li>Text that I want to scrape </li>
<li>Text that I want to scrape </li>
<li>Text that I want to scrape </li>
</ul>
</div>
,在这里我的代码
var productfeature =
document.DocumentNode.SelectNodes("//div[@class='content']/ul/li");
if (productfeature != null)
{
StringBuilder sb = new StringBuilder();
foreach (HtmlNode node in productfeature)
{
//Make sure nothing {} inside title
string safeint = node.InnerText.Replace("}", "").Replace("{","");
sb.Append(safeint + "}"); //adding } for marking
}
}
有些文章在这里 我说,它能够更好利用的string.join,buat我不知道如何与对象元素这样
NB:我想要的东西快ER和光..
使用实现'string.Join'将可能导致更清晰,更短的代码,但引擎盖下不应该进行明显的不同。 – Servy
在访问DOM的上下文中使用时,“更快更轻”是相当无意义的术语。这并不快,当然也不轻。避免无谓的优化。 –
以上两条评论都是正确的,但这会帮助你 http://stackoverflow.com/questions/585860/string-join-vs-stringbuilder-which-is-faster – prospector