<span style="font-size:18px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;//引入命名空间
using System.Threading.Tasks;
namespace 正则表达式
{
class Program
{
static void Main(string[] args)
{
string str = @"(0530|0530-)\d{7,8}";//定义的正则表达式符合条件为“0530”或
Console.WriteLine("请输入一个电话号码");//“0530-”开头,后面跟7位或8位数字
string tel = Console.ReadLine();
bool b;
b = Regex.IsMatch(tel,str);//判断是否符合正则表达式
if (b)
{
Console.WriteLine("{0}是某地的电话号码",tel);
}
else
{
Console.WriteLine("{0}不是某地的电话号码",tel);
}
Console.ReadLine();
}
}
}</span>
<span style="font-size:18px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string str = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";//定义的电子邮件地址的正则表达式
Console.WriteLine("请输入一个正确的Internet电子邮件地址");
string email = Console.ReadLine();
bool b;
b = Regex.IsMatch(email, str);//判断是否符合正则表达式
if (b)
{
string outstr = "";
outstr = Regex.Replace(email, "@", "AT");//进行替换
Console.WriteLine("替换后为:{0}", outstr);
}
else
{
Console.WriteLine("你所输入的字符串中不包括Internet URL");
}
Console.ReadLine();
}
}
}</span>
<span style="font-size:18px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string str = ";";//定义的正则表达式
Console.WriteLine("请输入多个用户姓名,以分号隔开");
string names = Console.ReadLine();
string[] name;
name = Regex.Split(names,str);
Console.WriteLine("分隔后的姓名为:");
foreach (string item in name)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}</span>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有