0

How can I get List() from this text:

For the iPhone do the following:<ul><li>Go to AppStore</li><li>Search by him</li><li>Download</li></ul>

that should consist :Go to AppStore, Search by him, Download

revolutionkpi
  • 2,632
  • 10
  • 45
  • 84

2 Answers2

5

Load the string up into the HTML Agility Pack then select all li elements inner text.

HtmlDocument doc = new HtmlDocument();
doc.LoadHtml("following:<ul><li>Go to AppStore</li><li>Search by him</li><li>Download</li></ul>");

var uls = doc.DocumentNode.Descendants("li").Select(d => d.InnerText);
foreach (var ul in uls)
{
    Console.WriteLine(ul);
}
carla
  • 1,970
  • 1
  • 31
  • 44
Oded
  • 489,969
  • 99
  • 883
  • 1,009
2

Wrap in an XML root element and use LINQ to XML:

var xml = "For the iPhone do the following:<ul><li>Go to AppStore</li><li>Search by him</li><li>Download</li></ul>";
xml = "<r>"+xml+"</r>"; 
var ele = XElement.Parse(xml);  
var lists = ele.Descendants("li").Select(e => e.Value).ToList();

Returns in lists:

Go to AppStore 
Search by him 
Download
yamen
  • 15,390
  • 3
  • 42
  • 52
  • 1
    +1 for using XML, though in small cases as this, is it not faster to just parse the string? –  May 11 '12 at 14:39