现在的位置: 首页 > 综合 > 正文

url 自动加入链接

2012年03月15日 ⁄ 综合 ⁄ 共 705字 ⁄ 字号 评论关闭
 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

抱歉!评论已关闭.