所以我有一个数组:
string[] myArray = txtStudentIDList.Text.Split(new Char[] { ',' });
for (int i = 0; i < myArray.Length; i++)
{
var ice = new DAL(Context, "UpdateData");
ice.AddParam("ClientID", myArray[i]);
}
}
这是字符串数组中有一些值,我想做的是这样的:
// eg myrray has the values of "1234","12344"
string Id = myarray myArray[i];
我希望这个 id 每次进入上面的 for 循环时都一个接一个地获取值,然后下次它进入循环时获取第二个值,以便它可以通过给定的客户端 ID 更新数据:例如:
// eg myrray has the values of "1234","12344"
1st time in the loop the id="1234" second time it comes in the look id = "12344"
现在的问题是,它将 Array 字符串中的所有内容放在一行中,如下所示:
id="1234rn12344"
我如何对此进行编码,使其不具有\r和所有值在一个字符串中,而是逐个。
看来 txtStudentIDList 不是一个逗号分隔的列表,而是一个 \r 分隔的列表。
更改第一行:
string[] myArray = txtStudentIDList.Text.Split(new Char[] { ',' });
自:
string[] myArray = txtStudentIDList.Text.Split(new string[] { "rn" }, StringSplitOptions.RemoveEmptyEntries);
一旦您的 myArray 对象具有适当的值,此处的其余代码应该按预期工作。
Split 方法在这里找到:https://msdn.microsoft.com/en-us/library/tabh47cf(v=vs.110).aspx