从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;
}
}
}
}
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;
}
}
}
}
相关文章推荐
- 19.从Email中提取用户名和域名:abc@163.com
- winform程序之两种从email中提取用户名和域名(简单)
- 黑马程序员之WinForm编程基础学习笔记:输入Email地址,输出用户名和域名。
- 3. 输入Email地址,输出用户名和域名。
- 从url中提取域名的几种方法
- 如何修改git全局初始化的用户名和邮箱? (git修改user.name 和user.email)
- 用RJS写的检测用户名和email是否存在
- Email地址,URL地址,电话号码提取规则
- 从指定的字符串中提取Email
- C#通过正规表达式提取html中的Email
- 用正则表达式提取URL里的域名,URI和参数
- jQuery实现自动输入email、时间和域名的方法
- 如何获取线程关联用户名和域名
- shell+curl监控网站页面(域名访问状态),并利用sendemail发送邮件
- 取得客户端的机器名,域名,登陆用户名...<转>
- 用户名文件夹后面有域名或计算机名
- 解决 Github用户名 变为 invalid-email-address 问题
- 从指定的字符串中提取Email
- IM开发【5】 - 使用email作为用户名登陆openfire
- 黄聪:用python知道URL地址提取链接中的域名与端口