C# 如何分割多个字符串

C# 如何分割多个字符串,c#,arrays,split,C#,Arrays,Split,我目前在C#中的代码方面遇到了问题。我想拆分没有固定值的字符串。这是我的代码,请帮我解决这个问题 protected void GridViewArchives_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView drView = (DataRowView)e.Row.DataItem

我目前在C#中的代码方面遇到了问题。我想拆分没有固定值的字符串。这是我的代码,请帮我解决这个问题

protected void GridViewArchives_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        DataRowView drView = (DataRowView)e.Row.DataItem;
        Literal litAuthors = (Literal)e.Row.FindControl("ltAuthors");

        string authors = drView["Author(s)"].ToString();
        //authors = Trent Riggs:Trent.Riggs@Emerson.com|Joel Lemke:Joel.Lemke@Emerson.com
        string[] splitauthors = authors.ToString().Split("|".ToCharArray());


        foreach (string authornames in splitauthors)
        {
            litAuthors.Text = string.Format("{0}<br /><br />", authornames);
        }
    }
}
受保护的void GridViewArchives\u RowDataBound(对象发送方,GridViewRowEventArgs e)
{
如果(e.Row.RowType==DataControlRowType.DataRow)
{
DataRowView drView=(DataRowView)e.Row.DataItem;
Literal litAuthors=(Literal)e.Row.FindControl(“ltAuthors”);
字符串authors=drView[“Author(s)”]。ToString();
//作者=特伦特·里格斯:特伦特。Riggs@Emerson.com|乔尔:乔尔。Lemke@Emerson.com
string[]splitauthors=authors.ToString().Split(“|”。.ToCharArray());
foreach(splitauthors中的字符串authornames)
{
litAuthors.Text=string.Format(“{0}

”,authornames); } } }
我在这里面临的问题是,当我呈现页面时,它只显示一个字符串值,而不显示数组中的后续字符串


在用“|”delimeter拆分字符串后,我想用delimeter拆分带有姓名和电子邮件地址的字符串:。如何执行此操作?

litAuthors.Text+=string.Format(“{0}

”,authornames)

litAuthors.Text+=string.Format(“{0}

”,authornames)

foreach(splitauthors中的字符串authornames)
{
litAuthors.Text=string.Format(“{0}

”,authornames); }
请检查
litAuthors.Text=string.Format(“{0}

”,authornames) 在for循环内部。 你应该使用

 litAuthors.Text +=  string.Format("{0}<br /><br />", authornames);
litAuthors.Text+=string.Format(“{0}

”,authornames);
foreach(splitauthors中的字符串authornames)
{
litAuthors.Text=string.Format(“{0}

”,authornames); }
请检查
litAuthors.Text=string.Format(“{0}

”,authornames) 在for循环内部。 你应该使用

 litAuthors.Text +=  string.Format("{0}<br /><br />", authornames);
litAuthors.Text+=string.Format(“{0}

”,authornames);
您可以使用该方法代替您的
foreach
循环:

string authors = drView["Author(s)"].ToString();
string[] splitAuthors = authors.Split('|');

litAuthors.Text = string.Join("<br /><br />", splitAuthors) + "<br /><br />";
您可以使用该方法代替
foreach
循环:

string authors = drView["Author(s)"].ToString();
string[] splitAuthors = authors.Split('|');

litAuthors.Text = string.Join("<br /><br />", splitAuthors) + "<br /><br />";
在用 “|”delimeter我想分开 带有名称和电子邮件地址的字符串 用测力计“:”。我该怎么办 这个

你是说这个吗

foreach (string authornames in splitauthors)        
{            
string[] authorDetails = authornames.Split(':');
litAuthors.Text += string.Format("{0}<br /><br />", authorDetails[0]);        
}
foreach(splitauthors中的字符串authornames)
{            
字符串[]authorDetails=authornames.Split(“:”);
litAuthors.Text+=string.Format(“{0}

”,authorDetails[0]); }
在用 “|”delimeter我想分开 带有名称和电子邮件地址的字符串 用测力计“:”。我该怎么办 这个

你是说这个吗

foreach (string authornames in splitauthors)        
{            
string[] authorDetails = authornames.Split(':');
litAuthors.Text += string.Format("{0}<br /><br />", authorDetails[0]);        
}
foreach(splitauthors中的字符串authornames)
{            
字符串[]authorDetails=authornames.Split(“:”);
litAuthors.Text+=string.Format(“{0}

”,authorDetails[0]); }
类似这样的东西

string authors = drView["Author(s)"].ToString();
//authors = Trent Riggs:Trent.Riggs@Emerson.com|Joel Lemke:Joel.Lemke@Emerson.com
string[] splitauthors = authors.ToString().Split("|".ToCharArray());


foreach (string author in splitauthors)
{
    string[] emailNameSplit = author.Split(":".ToCharArray());
    litAuthors.Text += string.Format("Name: {0} Email: {1}<br /><br />", emailNameSplit[0], emailNameSplit[1]);
}
string authors=drView[“Author(s)”].ToString();
//作者=特伦特·里格斯:特伦特。Riggs@Emerson.com|乔尔:乔尔。Lemke@Emerson.com
string[]splitauthors=authors.ToString().Split(“|”。.ToCharArray());
foreach(splitauthors中的字符串编写器)
{
字符串[]emailNameSplit=author.Split(“:”.ToCharArray());
litAuthors.Text+=string.Format(“名称:{0}电子邮件:{1}

”,emailNameSplit[0],emailNameSplit[1]); }
类似这样的东西

string authors = drView["Author(s)"].ToString();
//authors = Trent Riggs:Trent.Riggs@Emerson.com|Joel Lemke:Joel.Lemke@Emerson.com
string[] splitauthors = authors.ToString().Split("|".ToCharArray());


foreach (string author in splitauthors)
{
    string[] emailNameSplit = author.Split(":".ToCharArray());
    litAuthors.Text += string.Format("Name: {0} Email: {1}<br /><br />", emailNameSplit[0], emailNameSplit[1]);
}
string authors=drView[“Author(s)”].ToString();
//作者=特伦特·里格斯:特伦特。Riggs@Emerson.com|乔尔:乔尔。Lemke@Emerson.com
string[]splitauthors=authors.ToString().Split(“|”。.ToCharArray());
foreach(splitauthors中的字符串编写器)
{
字符串[]emailNameSplit=author.Split(“:”.ToCharArray());
litAuthors.Text+=string.Format(“名称:{0}电子邮件:{1}

”,emailNameSplit[0],emailNameSplit[1]); }