【问题标题】:Delete img path from description从描述中删除 img 路径
【发布时间】:2014-04-13 08:12:59
【问题描述】:

我需要来自 rss 提要的描述,但总是得到带有路径图像的描述。

RSS 提要是:

<description>
<![CDATA[<img src="http://example.com/img/1/title/1967304.jpg"/> Ukrainian forces launch an "anti-terrorist operation" after pro-Russian gunmen seize buildings in the eastern part of the country.]]>
</description>

我有代码:

if (this._groups.Count != 0)
   return;

SyndicationClient client = new SyndicationClient();
Uri feedUri = new Uri("url_feed");
var feed = await client.RetrieveFeedAsync(feedUri);
foreach (SyndicationItem item in feed.Items)
{
    string data = string.Empty;

    if (feed.SourceFormat == SyndicationFormat.Rss20)
    {
       // Get description
       data = item.Summary.Text;
    }
    Regex regx = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&amp;\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?.(?:jpg|bmp|gif|png)"
                            , RegexOptions.IgnoreCase);
    string filePath = regx.Match(data).Value;

    DataGroup group = new DataGroup(item.Id,
                                       item.Title.Text,
                                       item.Links[0].Uri.ToString(),
                                       filePath.Replace("small", "large"),
                                       data.Split(new string[] { "<br>" }, StringSplitOptions.None)[0].ToString());
    this.Groups.Add(group);
}

输出是(在文本块中):

在亲俄武装分子占领东部地区的建筑物后,乌克兰军队发起了“反恐行动”国家。

我只需要文本,不需要带有 img 路径的文本。

【问题讨论】:

    标签: c# rss windows-store-apps feed


    【解决方案1】:

    如果您的文本不包含“”,您可能会发现以下内容:

    使用:

    using System.Text.RegularExpressions;
    

    sn-p:

    // Do your stuff to get the description
    
    string description = "< img src=\"http://example.com/img/1/title/1967304.jpg\"> Ukrainian forces launch an \"anti-terrorist operation\" after pro-Russian gunmen seize buildings in the eastern part of the country.";
    
    string cleaned = Regex.Replace(description, @"<[^>]*>", String.Empty, RegexOptions.IgnoreCase).Trim();
    
    Console.WriteLine(cleaned);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-18
      • 2021-12-11
      • 1970-01-01
      相关资源
      最近更新 更多