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

从Email中提取出用户名和域名

2014-01-10 11:01 190 查看
从Email中提取出用户名和域名:xxx@126.com

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
// 从Email中提取出用户名和域名:xxx@126.com
// IndexOf找到@的位置。SubString
// 要考虑Email地址错误的情况

string email = Console.ReadLine();
if (!email.Contains("@") || email.StartsWith("@") || email.EndsWith("@"))
{
Console.WriteLine("Email地址格式不正确");
}
else {
int atIndex = email.IndexOf("@");
string username = email.Substring(0,atIndex);
string domain = email.Substring(atIndex+1);
Console.WriteLine("用户名:{0}\n域名:{1}",username,domain);
return;
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: