C#删除UL LI中指定标签里文字的方法

2019-12-30 17:43:20王冬梅

本文实例讲述了C#删除UL LI中指定标签里文字的方法。,具体如下:

现在需求越来越变态,但是做代码只能尽量满足,这里先是扣去ul和li中的超链接里的文字


PromptHtml = GetData.GetHTTPInfo(Config.Prompt_Url, "utf-8");
PromptHtml = PromptHtml.Replace("<ul><li>", "");
PromptHtml=PromptHtml.Replace("</li></ul>", "");
string ss = @"<a[sS]*?href=""([^" rel="external nofollow" "]*?)""[^>]*?>([sS]*?)</a>"; //这里
MatchCollection mcTable = Regex.Matches(PromptHtml, ss);
foreach (Match mTable in mcTable)
{
  if (mTable.Success)
  {
    PromptHtml = mTable.Groups[2].Value;
  }
}
resultHtml = PromptHtml;

具体的数据源如下:

复制代码 <ul><li><a href="http://www.easck.com/li></ul>", ""); string ss = @"<span>([^<]+)</span>"; //这里 MatchCollection mcTable = Regex.Matches(middlebannerHtml, ss); foreach (Match mTable in mcTable) { if (mTable.Success) { middlebannerHtml = mTable.Groups[1].Value; } } middleContent = middlebannerHtml;

具体的数据源如下:

 

复制代码 <ul><li><span>3年5倍涨幅的 不只是股票哦~</span> <a href="http://localhost/tg.aspx?ID=4195" rel="external nofollow" >立即查看</a></li></ul>

 

希望本文所述对大家C#程序设计有所帮助。


注:相关教程知识阅读请移步到c#教程频道。