這裏我需要創建一個gridview並從文本文件中添加值。文本文件包含電子郵件ID列表。在逐行顯示這些電子郵件ID後,我需要一個接一個地取出並用「@」字符分割。在接下來的列中,我需要顯示這些分割值。就像如下使用C#的Windows窗體中的DataGridView
Email username domain
[email protected] abcd gmail
[email protected] catdog gmail
這裏我需要創建一個gridview並從文本文件中添加值。文本文件包含電子郵件ID列表。在逐行顯示這些電子郵件ID後,我需要一個接一個地取出並用「@」字符分割。在接下來的列中,我需要顯示這些分割值。就像如下使用C#的Windows窗體中的DataGridView
Email username domain
[email protected] abcd gmail
[email protected] catdog gmail
創建Email
類:
public class Email
{
public Email(string email)
{
Address = email;
int index = email.IndexOf('@');
UserName = email.Substring(0, index);
Domain = email.Substring(index + 1);
}
public string Address { get; private set; }
public string UserName { get; private set; }
public string Domain { get; private set; }
}
而且網格數據綁定到該類的實例:
var emails = from line in File.ReadLines(fileName)
select new Email(line);
grid.DataSource = emails.ToList();
如果你需要第一列被命名爲Email
,然後手動添加列,併爲每列提供電子郵件類屬性的名稱,如DataPropertyName
。
UPDATE:目前已經存在MailAddress
類System.Net.Mail命名空間,你可以使用同樣的目的:
var emails = from line in File.ReadLines(fileName)
select new MailAddress(line);
它具有性能Address
,User
和Host
它滿足您的需求。
非常感謝@lazybereZovsky ...對不起,我忘了發佈我的編碼 – yasmuru
您可以僱用某人,我們不會爲您編寫代碼。 – FSou1
你嘗試過什麼,或者它只是做我的作業問題? –
當您提問時,請提供您已有的代碼。 –