首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎么截取这样的字段

2012-04-26 
如何截取这样的字段我想在读取的字段数据中,截取第一个图片的路径/upshop/201109/24100019201.jpg,请问如

如何截取这样的字段
我想在读取的字段数据中,截取第一个图片的路径/upshop/201109/24100019201.jpg,请问如何截取啊


<p>
 龙年买恐龙</p>
<p style="text-align: center">
 <img alt="恐龙" src="/upshop/201109/24100019201.jpg" style="width: 550px; height: 413px" /></p>
<p style="text-align: center">
 <img alt="恐龙" src="/upshop/201109/24100019592.jpg" style="width: 600px; height: 450px" /></p>
<p style="text-align: center">
 <img alt="恐龙" src="/upshop/201109/24100019543.jpg" style="width: 600px; height: 450px" /></p>
<p style="text-align: center">
 <img alt="恐龙" src="/upshop/201109/24100019934.jpg" style="width: 550px; height: 413px" /></p>
<p style="text-align: center">
 &nbsp;</p>


[解决办法]

C# code
string input = @"<p> 龙年买恐龙</p><p style=""text-align: center""> <img alt=""恐龙"" src=""/upshop/201109/24100019201.jpg"" style=""width: 550px; height: 413px"" /></p><p style=""text-align: center""> <img alt=""恐龙"" src=""/upshop/201109/24100019592.jpg"" style=""width: 600px; height: 450px"" /></p><p style=""text-align: center""> <img alt=""恐龙"" src=""/upshop/201109/24100019543.jpg"" style=""width: 600px; height: 450px"" /></p><p style=""text-align: center""> <img alt=""恐龙"" src=""/upshop/201109/24100019934.jpg"" style=""width: 550px; height: 413px"" /></p><p style=""text-align: center""> &nbsp;</p>";            Regex rgx = new Regex(@"(?is)(?<=src="")[^""]+?(?="")");            Console.WriteLine(rgx.Match(input));
[解决办法]
探讨

C# code

string input = @"<p>
龙年买恐龙</p>
<p style=""text-align: center"">
<img alt=""恐龙"" src=""/upshop/201109/24100019201.jpg"" style=""width: 550px; height: 413px"" /></p>
<p style=""text-align: ……

[解决办法]
探讨

C# code

string input = @"<p>
龙年买恐龙</p>
<p style=""text-align: center"">
<img alt=""恐龙"" src=""/upshop/201109/24100019201.jpg"" style=""width: 550px; height: 413px"" /></p>
<p style=""text-align: ……

[解决办法]

<p>
 龙年买恐龙</p>
<p style="text-align: center">
 <img alt="恐龙" src="/upshop/201109/24100019201.jpg" style="width: 550px; height: 413px" /></p>
<p style="text-align: center">
 <img alt="恐龙" src="/upshop/201109/24100019592.jpg" style="width: 600px; height: 450px" /></p>
<p style="text-align: center">
 <img alt="恐龙" src="/upshop/201109/24100019543.jpg" style="width: 600px; height: 450px" /></p>


<p style="text-align: center">
 <img alt="恐龙" src="/upshop/201109/24100019934.jpg" style="width: 550px; height: 413px" /></p>
<p style="text-align: center">
 &nbsp;</p>

jquery来操作,更方便,记得将jquery.js引入即可

<script type="text/javascript">
$(function(){
var v = $("img:first").attr("src");
alert(v);
});
</script>

热点排行