Reputation: 212
Best method joining string inside Object ( HTMLcollection )? I using microsoft studio 2008, NET 3.5, with HTMLagilityPack
Here the 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>
and here my code
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
}
}
Some article in here said, its better using string.join, buat I dont know how to doing this with object element
NB: I want something faster and light..
Upvotes: 0
Views: 224
Reputation: 203834
Here is an implementation using string.Join
string delimiter = safeint + "}";
string result = "{" + string.Join(delimiter,
productfeature.Select(node => removeBraces(node.InnerText)).ToArray()) + "}";
public static string removeBraces(string value)
{
return value.Replace("}", "").Replace("{", "");
}
Upvotes: 1