比较我现在的string数组里有2W条数据,我想每1000条一组拆出来,处理,我要怎么做呢...脑洞好闭塞啊...
1
mwylaoma 2015-06-18 12:45:25 +08:00
split,for循环,if == 1000,处理
|
2
zkd8907 2015-06-18 12:51:57 +08:00
同一楼。如果想花式一点的也可以考虑用linq2object
var all = new string[20000]; string[] items; for (var i = 0; i < 20; ++i) { items = all.Skip(i).Take(1000).ToArray(); } |
3
guanyongxin OP public static void SplitStr(int count,ArrayList list)
{ try { if (count > list.Count) { PutInHtml((string[])list.ToArray(typeof(string))); return; } Random r = new Random(); int z = list.Count / count; ArrayList yu = new ArrayList(); int start = list.Count; for (int i = 0; i < start; i++) { yu.Add(list[i]); list.RemoveAt(i); if (list.Count % count == 0) { PutInHtml((string[])yu.ToArray(typeof(string))); Thread.Sleep(r.Next(1000, 4500)); break; } } var all = (string[])list.ToArray(typeof(string)); string[] items; string info = string.Empty; for (var i = 0; i < z; ++i) { items = all.Skip(i).Take(count).ToArray(); PutInHtml(items); Thread.Sleep(r.Next(1000, 4500)); } } catch { } } 这样处理了,先把余数解决,之后可以整除的就用楼上的方法 |
4
caoyue 2015-06-18 20:37:51 +08:00
用 Linq 大概只需要一行
p = 1000 Enumerable.Range(0, (list.Count()+p-1)/p).ToList().ForEach(x=>PutInHtml(a.Skip(p*x).Take(p))); |
5
guanyongxin OP @caoyue ling不会.....
|