I am not sure what this is called so Ill explain by giving an example. I have an array of numbers
76425
234786234
56
4356
564356
456
94
900
725
Now I would like to join this data and make a new array that looks like this
76425,234786234,56,4356
564356,456,94,900
725
This is a string array that contains 3 items. Items per row is 4. As you can see the last row only has one item. That is ok. Here is the code I have written to do this:
numberOfColumns = numberOfColumns > lineCount ? lineCount : numberOfColumns;
int newLineCount = Convert.ToInt32(Math.Ceiling((Convert.ToDouble(lineCount))/numberOfColumns));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < newLineCount; i++)
{
var page = lines.Skip(numberOfColumns * i).Take(numberOfColumns).Select(xx => xx.Trim());
sb.AppendLine(string.Join(",",page));
}
This code works just fine. But it is very slow. Do you have any ideas to make it faster.
Are you looking for something like this?