Extract image URL in a string (RSS with syndicationfeed)

跟風遠走 提交于 2019-12-14 03:32:31

问题


i have this :

<img src="http://MyUrl.JPG.jpg" width="180" ...

and i need this :

http://MyUrl.JPG.jpg

thank


回答1:


Complete solution with regex :

string source ="<img src=\"http://MyUrl.JPG.jpg\"";
var reg = new Regex("src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\"|\')?");
var match=reg.Match(source);
if(match.Success)
{
  var encod = match.Groups["imgSrc"].Value;
}



回答2:


If that's really all you have you might get away with a regular expression, like

src="([^"]+)

However, you can't and shouldn't try to parse HTML in general with regular expressions. Using regular expressions to parse HTML: why not?

Instead use an HTML parser like Html Agility Pack. I don't know if it's available for WP7, though.



来源:https://stackoverflow.com/questions/9517323/extract-image-url-in-a-string-rss-with-syndicationfeed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!