Sun_china

交流更多,收获更多?

博客园 首页 新随笔 联系 订阅 管理
 1string strContent = TextBox1.Text;
 2
 3            //(http:\/\/([\w.]+\/?)\S*)
 4            //http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
 5
 6            //都是匹配url的正则
 7            Regex urlregex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)",RegexOptions.IgnoreCase| RegexOptions.Compiled);
 8            
 9            System.Text.RegularExpressions.MatchCollection match=urlregex.Matches(strContent);
10        
11            for(int i=0;i<match.Count;i++)
12            {
13                //"<a href=\"\" target=\"_blank\"></a>");
14                strContent = strContent.Replace(match[i].Value,"<a href=\""+match[i].Value+"\">"+match[i].Value+"</a>");
15            }

16            Label1.Text+= "<br>"+strContent;
17
posted on 2007-05-15 14:06  Sun_china  阅读(227)  评论(0编辑  收藏  举报