我有一个字符串,看起来像"a,b,c,d,e,1,4,3,5,8,7,5,1,2,6等等。我正在寻找最好的方法来拆分它,使它看起来像这样:
A、B、C、D、E
1 4 3 5 8
7 5 1 2 6
在进阶时谢谢
发布于 2016-04-12 13:52:33
假设您有固定的列数(5):
string Input = "a,b,c,d,e,11,45,34,33,79,65,75,12,2,6";
int i = 0;
string[][] Result = Input.Split(',').GroupBy(s => i++/5).Select(g => g.ToArray()).ToArray();首先,我按字符拆分字符串,然后将结果分组为5个项目的块,并将这些块选择为数组。
结果:
a b c d e
11 45 34 33 79
65 75 12 2 6要将结果写入到文件中,您必须
using (System.IO.StreamWriter writer =new System.IO.StreamWriter(path,false))
{
foreach (string[] line in Result)
{
writer.WriteLine(string.Join("\t", line));
}
}; https://stackoverflow.com/questions/36564525
复制相似问题