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

求个函数.
由富文本编辑框,..编辑内容后,..为html内容.

现在求个函数,能把内容中第一张图片,取出来,即取出它的地址...

谢谢...

------解决方案--------------------
使用正则表达式吧

取出编辑后的一串html字符串,假设放在变量s中

C# code

string s = @".......<IMG id=abc border=0 src='http://localhost/Uploads/2010/08/a197b6e6-bb21-4ee1-8d23-f232af148bd1.gif'>";
Regex reg = new Regex(@"(?i)<img[^>]*?src=(['""]?)([^'""\s>]+)\1[^>]*>");
Match m = reg.Match(s);
if (m.Success)
{
     richTextBox2.Text = m.Groups[2].Value; //这里就是src中的图片路径值
}

------解决方案--------------------
另一种使用函数,请参考:
http://yunxingfengzw--007.blog.163.com/blog/static/16484003201131485852997/