从c#中的字符串中删除URl

时间:2011-04-04 11:05:33

标签: c# windows-phone-7

我有一个我从RSS提要中解析的字符串

thumbnail url='http://photos3.media.pix.ie/11/C5/11C5B77C92204ADBBD0CF5FDF4BA351B-0000314357-    0002211156-00240L-00000000000000000000000000000000.jpg' height='240' width='226'

我需要从字符串中删除URL详细信息,以形成Windows Phone 7应用程序中图像的基础。

你认为最好的做法是什么

手机的代码在这里

        FeedItems.ItemsSource = from imageFeed in xmlImageEntries.Descendants("item")
                                 select new PixIEPanoramaTest.Data.FeedItem
                                 {
                                     ThumbSource = imageFeed.Element("thumbnail").Value,

                                 };

Feeditems只是一个绑定列表框。 thumbsource变量只需要字符串中的URL。

任何想法都非常感激,

罗布

2 个答案:

答案 0 :(得分:2)

您只需访问网址属性的属性值:

ThumbSource = imageFeed.Element("thumbnail").Attribute("url").Value,

如果缺少该属性,可能值得使用某种扩展方法返回string.Empty

答案 1 :(得分:0)

有些库可用于帮助解析RSS提要 - 例如

如果你想自己快速“hacky”解析字符串,那么你可以使用RegularExpressions - 例如类似thumbnail url='(?<imageurl>http.*?)' height='240' width='226'的正则表达式会将您的网址拉出imageurl

Match match = Regex.Match(input, @"thumbnail url='(?<imageurl>http.*?)' height='240' width='226'");

if (match.Success)
{
    string url = match.Groups[1].Value;
}