首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从描述中删除img路径

从描述中删除img路径
EN

Stack Overflow用户
提问于 2014-04-13 08:12:59
回答 1查看 273关注 0票数 1

我需要从rss提要描述,但始终得到一个描述与路径图像。

RSS提要是:

代码语言:javascript
复制
<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>

我有密码:

代码语言:javascript
复制
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 src="">http://example.com/img/1/title/1967304.jpg">乌克兰部队在亲俄枪手占领乌克兰东部的建筑物后发动了“反恐行动”。

我只需要文字,没有文字与img路径。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-13 08:34:35

如果您的文本不包含“<”或“doesn>”,您可能会发现这是有用的:

使用:

代码语言:javascript
复制
using System.Text.RegularExpressions;

片段:

代码语言:javascript
复制
// 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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23040422

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档