本帖最后由 The_Enternal 于 2014-7-12 17:30 编辑
- <div><span style="line-height: 1.5; background-color: rgb(247, 247, 247);">using System;</span></div><span style="line-height: 1.5; background-color: rgb(247, 247, 247);">using System.Collections.Generic;</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);">using System.Text;</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);">namespace 邮箱地址</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);">{</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> class Program</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> {</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> static void Main(string[] args)</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> {</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> Console.WriteLine("请输入邮箱地址:");</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> string mail = Console.ReadLine();</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> string userName, domainName;</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> //判断用户名中是否含有"@"字符</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> if (mail.LastIndexOf("@") !=mail.IndexOf("@"))</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> {</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> //字符串中"@"的第一个索引和最后一个索引值不相等,则表示含有两个"@"字符</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> //从开头到最后一个"@"字符以前的字符串都是用户名</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> userName = mail.Substring(0, mail.LastIndexOf("@"));</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> //最后一个"@"字符往后都是域名</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> domainName = mail.Substring(mail.LastIndexOf("@") + 1);</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> }</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> else</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> {</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> //只含有一个"@"字符,直接从"@"字符的索引处分割</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> userName = mail.Substring(0, mail.IndexOf("@"));</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> domainName = mail.Substring(mail.IndexOf("@") + 1);</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> }</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> Console.WriteLine("——————————————————————");</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> Console.WriteLine("用户名:{0},域名:{1}",userName,domainName);</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> Console.ReadKey();</span><span style="background-color: rgb(247, 247, 247);">
- </span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> }</span><div><span style="line-height: 1.5; background-color: rgb(247, 247, 247);"> }</span></div><div><span style="line-height: 1.5; background-color: rgb(247, 247, 247);">}</span><span style="line-height: 1.5; background-color: rgb(247, 247, 247);">
- </span></div>
复制代码
|