Split Array of string at every 20th item


I’m trying to split an array of strings (based on pdffiles in a folder) for every 20 items.

So far I’ve made this
ArrString = directory.getfiles(“path”)
should I go for a for each activity combines with the index or is it possible to divide the array into 20 items each

Lets say there is 89 files in folder, I would like to get 5 strings commaseparated containing the paths of
20 files
20 files
20 files
20 files
9 files
lastly the 5 strings should be used to combine the 20 pdffiles into 1 pdf file.

How would it be best to approach this?

You can handle this inside a for loop using a counter. Every time the counter reaches 20, reset it and store the string. Or you could use LINQ to do this.

Just to know, why are you doing this? Windows by default has a character limit of 255 - 260 in a file path. You can override it, but just wanted to point that out.

lets assume following:

Convert.ToInt32(Math.Ceiling(arrStrings.Length/ SegmentSize))

(From i In Enumerable.Range(0,NoOfSegments).ToList
Select arrStrings.Skip(i*SegmentSize).Take(SegmentSize).toArray).toList


find starter help here:
List_TakeSkip.xaml (5.4 KB)


Hi Peter

Thats absolutely excellent, works perfect. Thank you very much.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.