如何从电子邮件地址中查找用户和主机(字符串不是MailAddress) [英] How to find User and Host from an email address (string not MailAddress)
问题描述
我需要从给定的电子邮件地址中找到主机名和用户名。
如果我可以完成此任务,我正在编写要上传的库/控件集。
这是我需要找到的一个例子:
假设我们有我的电子邮件:shelby.p67@gmail.com
'@'符号分隔用户来自主机名'gmail.com'的'shelby.p67'。
问题:
我正在为控件构建一个类而不想使用System .Net框架提供的.Net.Mail.MailAddress类。第三方图书馆不会这样做,因为这只是我不知道正常表达的问题。
I need to find the Host Name and Username from a given email address.
I'm writing a library/control set to upload if I can finish this task.
Here's an example of what I need to find:
Say we have my email: shelby.p67@gmail.com
The '@' symbol seperates the the user 'shelby.p67' from the host name 'gmail.com'.
Problem:
I'm building a class for a control and don't want to use System.Net.Mail.MailAddress class that the .Net framework provides. Third party libraries won't do because this is a matter of me just not knowing RegularExpressions aswell as I thought.
推荐答案
我认为这有效,而不是100%肯定。
I think this works, not 100% sure.
public string Address
{
get
{
if (_user != null && _host != null)
return _user + "@" + _host;
else
return _address;
}
set
{
_address = value;
if (IsValidEmail(_address))
{
int atIndex = _address.IndexOf('@');
_user = _address.ToString().Substring(0,atIndex);
_host = _address.ToString().Substring(atIndex, _address.Length - atIndex);
}
else
_user = _host = null;
}
}
这篇关于如何从电子邮件地址中查找用户和主机(字符串不是MailAddress)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!