繁体   English   中英

遍历字符串Array一次获取每个项目

[英]Loop through the string Array take each item at a time

所以我有一个数组:

   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="1234\\r\\n12344"如何将其编码为没有\\ r \\ n和所有值放在一个字符串中,而是一个接一个。

看来txtStudentIDList不是逗号分隔的列表,而是\\ r \\ n分隔的列表。

更改第一行:

string[] myArray = txtStudentIDList.Text.Split(new Char[] { ',' });

至:

string[] myArray = txtStudentIDList.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

一旦myArray对象具有适当的值,此处的其余代码将按预期工作。

在此处找到分割方法: https : //msdn.microsoft.com/zh-cn/library/tabh47cf(v=vs.110).aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM