c#将1,2,3,4,5,6,7,8 拆分为1,2 和 3,4 和 5,6 和 7,8

//将一段以,分割的字符每次 取连续的2个字符
            string str = "1, 2, 3, 4, 5, 6, 7, 8, 9, 10"; //原始字符串
            string[] a = str.Split(',');
            List<string> b = new List<string>(a);
            for (int i = 0; i < a.Length/2; i++)
            {
                string[] c = new string[2];
                for (int j = 0; j < 2; j++) //每次取两个
                {
                    c.SetValue(b[0].Trim(),j);
                    b.RemoveAt(0);
                }
                string d = c[0] + "," + c[1];//每次的结果 1,2   3,4  ....
            }

猜你喜欢

转载自blog.csdn.net/qq_36729112/article/details/88734586