【发布时间】:2014-08-22 06:16:31
【问题描述】:
我有一个文件,其中包含文本。我需要搜索一个字符串并提取该行上的 href。
file.txt 是包含基本 wordpress 主页的文件
最后我想要http://example.com 链接。 我尝试了几种方法,例如
DateTime dateTime = DateTime.UtcNow.Date;
string stringpart = dateTime.ToString("-dd-M-yyyy");
string finalword = "candy" + stringpart;
List<List<string>> groups = new List<List<string>>();
List<string> current = null;
foreach (var line in File.ReadAllLines(@"E:/file.txt"))
{
if (line.Contains("-22-8-2014") && current == null)
current = new List<string>();
else if (line.Contains("candy") && current != null)
{
groups.Add(current);
current = null;
}
if (current != null)
current.Add(line);
}
foreach (object o in groups)
{
Console.WriteLine(o);
}
Console.ReadLine();
}
【问题讨论】:
-
你应该尝试使用HTML Agility Pack来解析html
-
谢谢,我试试看!
标签: c# string web-services find