我需要来自rss feed的说明,但始终会获得路径图片的说明。
RSS Feed是:
<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\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?.(?: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);
}
输出是(在文本块中):
&LT; img src =“http://example.com/img/1/title/1967304.jpg”&gt;亲俄罗斯武装分子占领该国东部的建筑后,乌克兰军队开展了“反恐行动”。
我只需要文本,没有带img路径的文本。
答案 0 :(得分:0)
如果您的文字不包含&#39;&lt;&#39;或者&#39;&gt;&#39;你可能会发现这个usfull:
使用:
using System.Text.RegularExpressions;
片段:
// 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);