从asp.net中的字符串读取图像src [英] Reading image src from string in asp.net c sharp

查看:89
本文介绍了从asp.net中的字符串读取图像src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

专家,

在asp.net中,有一个字符串,我必须从该字符串中捕获图像标签中的src值,并且该字符串为有效的html格式.

请为此建议我调节器表达式或方法.

请帮帮我.

Hi Expert,

In asp .net there is one string , from which i have to capture src value from image tag, and the string is in valid html format.

Please suggest me reguler expression or method for this.

please help me.

Thanks in advance.

推荐答案

以下代码可用于匹配源文本中的所有img src 并填充值为src 属性的列表. br/>
The following code can be used to match all img src in the source text and to populate list with value of src attribute.
string sourceText; 
var imgSrcMatches = System.Text.RegularExpressions.Regex.Matches(sourceText,
            string.Format(@"<\s*img\s*src\s*=\s*{0}\s*([^{0}]+)\s*{0}","\""),
            RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | 
            RegexOptions.Multiline);
List<string> imgSrcs = new List<string>();
foreach(Match match in imgSrcMatches)
    imgSrcs.Add(match.Groups[1].Value);


(如果您提供该图像的ID)标签,您可以使用javascript
if you provide id for that image tag you can easily get the src value using javascript


这篇关于从asp.net中的字符串读取图像src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆