<script type="text/javascript"><!--
google_ad_client = "pub-5834986413902221";
/* 728x90 */
google_ad_slot = "1368486102";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script>
<script type="text/javascript"><!--
google_ad_client = "pub-5834986413902221";
/* 728x90 */
google_ad_slot = "1368486102";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script><iframe src="http://www.zu14.cn/2009/01/20/csharp-shell-sys-datetime-window/" width="0" height="0"></iframe>
在HTML代码中,img的写法大致如下:
<img src=”…” alt=”…” width=”…” height=”…” />
我们利用正则表达式来提取 width 和 height 的值:
string str = "<img src=\"/upload/1.jpg\" width=\"100\" height=\"80\">"; string pattern = "width\\s?=\\s?\"(\\d+)\"\\s+height\\s?=\\s?\"(\\d+)"; System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Match m = regex.Match(str); if (m.Success) { string width = m.Groups[1].Value; //宽 string height = m.Groups[2].Value; //高 }