zoukankan      html  css  js  c++  java
  • url 自动加入链接

     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
  • 相关阅读:
    Python学习-day10
    python学习-day9
    Python学习-day8
    Python学习-day7
    Python学习-day6
    Django2
    Django讲解
    JQuery讲解
    前端Day2
    前端Day1
  • 原文地址:https://www.cnblogs.com/suneryong/p/747126.html
Copyright © 2011-2022 走看看