您的位置:首页 > 大数据 > 人工智能

简单判断邮箱格式 contains包括 IndexOf(“@”)

2015-04-03 08:50 288 查看
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
while (true)
{
string email = Console.ReadLine();
if (email.Contains("@") && (email.Contains(".com") || email.Contains(".cn")))//是否包括@、.com、.cn
{
int index = email.IndexOf("@");//IndexOf查找“@”在第几个下标
Console.WriteLine("您输入的邮箱正确!");
Console.WriteLine("您的邮箱用户名为:" + email.Substring(0, index));
}
else
{
Console.WriteLine("您输入的邮箱不正确!");
}
}

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: