【发布时间】:2013-10-29 13:55:48
【问题描述】:
我有一个由 First Name _ Last Name 组成的数组,因此它们会像这样读取 迈克尔·乔丹 哈维尔_洛佩兹 乔治_琼斯
我有一个循环设置来遍历其中的每一个,但我只想获取“”之后的内容我遇到的问题是该数组是全局声明的,并且它被声明为远很多地方让我改变。如果我尝试使用 .Split 函数,我会收到 System.Array 不包含拆分定义的错误。获取数组中“”之后的数据的另一种选择是什么?
public static string GetEmployees()
{
string queryString = "select employeeName from tbl_GlobalEmployeeData where state = 'AL';
SqlConnection connection = new SqlConnection(Connection.MyConnectionString.ConnectionStrings[0]);
{
SqlCommand cmd = new SqlCommand(queryString, connection);
connection.Open();
List<string> tempList = new List<string>();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
try
{
if (!reader.IsDBNull(0))
{
tempList.Add(reader[0].ToString() + "_" + reader[1].ToString());
}
}
catch
{
if (!reader.IsDBNull(0))
{
tempList.Add(reader[0].ToString() + "_" + reader[1].ToString());
}
}
}
reader.Close();
AllCompanyEmployees.State.ThisStore = tempList.ToArray();
for (int q = AllCompanyEmployees.State.ThisStore.GetLowerBound(0); q <= AllCompanyEmployees.State.ThisStore.GetUpperBound(0); q++)
{
return AllCompanyEmployees.State.ThisStore[q];
}
return null;
}
}
}
for (int q = AllCompanyEmployees.State.ThisStore.GetLowerBound(0); q <= AllCompanyEmployees.State.ThisStore.GetUpperBound(0); q++)
{
//This line is where I get the error mentioned above
string lastName = AllCompanyEmployees.State.ThisStore.Split('_')[1];
}
【问题讨论】:
-
我看不到您的问题与代码之间的联系。你是不是贴错了sn-p?
-
""之后?一无所有之后?你在说什么?你的意思是在下划线上分开吗?请显示您的全局数组的代码,并阐明您要对示例执行的操作。此外,您不能在数组上使用Split。这是String的一种方法。您需要在数组中的各个字符串上使用Split。 -
向试图提供帮助的 2 人道歉,我确实发布了错误的代码 sn-p。请查看我的编辑中发布的代码。
-
还有很多未解决的问题。在您回复之前无法回答您的问题。
-
我想拆分数组 - 例如它读取 Javier_Lopez 我想从数组中取出 Lopez。