⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class1.cs

📁 C#2005 实例源代码
💻 CS
字号:
using System;
using System.Text.RegularExpressions;

namespace Example_ValidateUrl
{
	/// <summary>
	/// 验证一个URL的合法性
	/// </summary>
	class MainTest
	{
		public bool ValidateUrl(string _strUrl)
		{			
			string patten = @"^http://(www\.){0,1}.+\.(com|net|cn)$";	//正则表达式
			
			Regex r = new Regex(patten);					//声明一个Regex对象			
			Match m = r.Match(_strUrl);						//使用Match方法进行匹配
			if(m.Success)									//匹配成功
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			MainTest t=new MainTest();
			string strUrl="http://www.php.net";
			Console.WriteLine(t.ValidateUrl(strUrl));
			

		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -