当前位置: 代码迷 >> ASP.NET >> 怎么截取这样的字段
  详细解决方案

怎么截取这样的字段

热度:7380   发布时间:2013-02-25 00:00:00.0
如何截取这样的字段
我想在读取的字段数据中,截取第一个图片的路径/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>
  相关解决方案