[C#] c#自动识别URL网址的代码 →→→→→进入此内容的聊天室

来自 , 2019-04-07, 写在 C#, 查看 115 次.
URL http://www.code666.cn/view/88f0bf28
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Net;
  5. using System.Text.RegularExpressions;
  6. namespace ConsoleApplication3
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.            
  13.             string s = "例如:http://www.asd.com";
  14.             Regex re = new Regex(@"(?<url>http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?)");
  15.             MatchCollection mc = re.Matches(s);
  16.             foreach (Match m in mc)
  17.             {
  18.                 s=s.Replace(m.Result("${url}"), String.Format("<a href='{0}'>{0}</a>", m.Result("${url}")));
  19.             }
  20.             Console.WriteLine(s);
  21.         }
  22.     }
  23. }
  24. //csharp/5524

回复 "c#自动识别URL网址的代码"

这儿你可以回复上面这条便签

captcha