首页 新闻 会员 周边 捐助

求帮忙:C# 替换所有img的src属性,并添加一个属性

0
悬赏园豆:30 [已关闭问题] 关闭于 2014-04-02 14:14
 1 <div class="activity_banner">
 2         <img src="http://act.shangpin.com/brand/Activities/201402270310bluegirl/images/img01.jpg" width="1900" height="540" border="0" />
 3     </div>
 4     <div class="activity_wp_cn">
 5         <img src="http://act.shangpin.com/brand/Activities/201402270310bluegirl/images/img02.jpg" width="960" height="400" border="0" />
 6         <img src="http://act.shangpin.com/brand/Activities/201402270310bluegirl/images/img03.jpg" width="960" height="400" border="0" />
 7         <img src="http://act.shangpin.com/brand/Activities/201402270310bluegirl/images/img04.jpg" width="960" height="400" border="0" />
 8      </div>

我想变成

1 <div class="activity_banner">
2         <img src="/aolai/images/e.gif" lazy="http://act.shangpin.com/brand/Activities/201402270310bluegirl/images/img01.jpg" width="1900" height="540" border="0" />
3     </div>
4     <div class="activity_wp_cn">
5         <img src="/aolai/images/e.gif" lazy="http://act.shangpin.com/brand/Activities/201402270310bluegirl/images/img02.jpg" width="960" height="400" border="0" />
6         <img src="/aolai/images/e.gif" lazy="http://act.shangpin.com/brand/Activities/201402270310bluegirl/images/img03.jpg" width="960" height="400" border="0" />
7         <img src="/aolai/images/e.gif" lazy="http://act.shangpin.com/brand/Activities/201402270310bluegirl/images/img04.jpg" width="960" height="400" border="0" />
8     </div>

用正则怎么写呀?多谢各位帮忙啊~~!

糯米糍的主页 糯米糍 | 初学一级 | 园豆:154
提问于:2014-04-02 13:14
< >
分享
所有回答(2)
0

这个不难

lucika.zh | 园豆:54 (初学一级) | 2014-04-02 13:19
0

经测试通过:

static void Main(string[] args)
        {
            Regex r = new Regex("http:.*?\"");
            string source ="<img src=\"http://act.shangpin.com/brand/Activities/201402270310bluegirl/images/img01.jpg\" width=\"1900\" height=\"540\" border=\"0\" />";
            string dest = r.Replace(source, new MatchEvaluator(x =>"/aolai/images/e.gif\" lazy=\""+ x.ToString()));
            Console.Read();
        }
hexllo | 园豆:318 (菜鸟二级) | 2014-04-02 14:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册