日期:2014-05-17  浏览次数:20416 次

遍历取图片的路径问题
我通过文本编辑id=content添加了几个图片(不定)
得到的文本内容为:
<p>
as
</p>
<p>
<img style="float:none" title="1111你好" src="/upload/images/20120822144451781.jpg" />
</p>
<p>
<img style="float:none" title="222您也好" src="/upload/images/20120822144451843.jpg" />
</p>
<p>

</p>

我怎么才能提取成这样的格式呢?
/upload/images/20120822144451781.jpg|1111你好,/upload/images/20120822144451843.jpg|222您也好
也就是我最终的目的就是只需得到图片的路径和它的说明,以便存在数据表的一个字段里

------解决方案--------------------
JQuery去获取

var str="";
$("img").each(function(){str+=this.attr("src")+this.attr("title");});
------解决方案--------------------
C# code

Regex r = new Regex("<img[^>]+title=\"([^\"]*)\" src=\"([^\"]*)\"[^>]+/>");
        string str = "<p>as</p><p><img style=\"float:none\" title=\"1111你好\" src=\"/upload/images/20120822144451781.jpg\" /></p><p><img style=\"float:none\" title=\"222您也好\" src=\"/upload/images/20120822144451843.jpg\" /></p><p></p>;}";
        MatchCollection mc =r.Matches(str);
        string s = "";
        foreach (Match m in mc)
        {
            s += m.Groups[2] + "|" + m.Groups[1] + ",";           
        }
        string aa = s.TrimEnd(',');
//aa=/upload/images/20120822144451781.jpg|1111你好,/upload/images/20120822144451843.jpg|222您也好

------解决方案--------------------
探讨

<p>
<img style="float:none" title="1" src="/upload/images/20120822162206703.jpg" />
</p>
<p>
<img style="float:none" title="22" src="/upload/images/20120822162206703.jpg" />
</p>……