如何使用正则表达式解析字符串
本文关键字:字符串 正则表达式 何使用 | 更新日期: 2023-09-27 18:33:49
如何从本文中获取List():
For the iPhone do the following:<ul><li>Go to AppStore</li><li>Search by him</li><li>Download</li></ul>
应该包括:转到应用商店, 被他搜索, 下载
将字符串加载到 HTML Agility Pack 中,然后选择所有li
元素内部文本。
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);
}
包装 XML
根元素并使用 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();
lists
退货 :
Go to AppStore
Search by him
Download