62,025
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Con1
{
class Program
{
public static String GetWebName(String url)
{
string name = "";
Regex rx = new Regex(@"http://(?<name>(\w+.)+.\w{2,3})/", RegexOptions.Compiled | RegexOptions.IgnoreCase);
MatchCollection matches = rx.Matches(url);
if (matches.Count > 0)
name = matches[0].Groups["name"].Value;
return name;
}
static void Main(string[] args)
{
String tests = "http://www.haokan123.com/ ";
Console.WriteLine("The WebName Of {0} Is: {1}", tests, GetWebName(tests));
Console.ReadLine();
}
}
}