TomDev
TomDev

Reputation: 15

Delete img path from description

I need description from rss feed, but always get a description with path image.

RSS feed is:

<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>

I have code:

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);
}

And output is (in textblock):

< 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.

I need only text, no text with img path.

Upvotes: 1

Views: 288

Answers (1)

Jossef Harush Kadouri
Jossef Harush Kadouri

Reputation: 34217

If your text doesn't contain '<' or '>' you may find this usfull:

using:

using System.Text.RegularExpressions;

snippet:

// 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);

Upvotes: 0

Related Questions