Get Range from Datatable Set to Array

Hi I have a datatable that is structured like this.


Now I would like to put the rows from F-row to before F-row into an array without iterating over each row and putting the result at the end of the string.

It should look like this

Array[{F-row, G-row, K-row, K-row, G-row, K-row}, {F-row, …}] (hope the bracket syntax is correct but you know what I mean :wink: )
(Important is that the number of rows between F and F can be different)

I don’t really care about the data type of the array element but DT would be nice.

Unfortunately I didn’t find out with the select function how this can be done (if this is possible).

1 Like

Hi @MarioHerrmann

Can you provide the sample output and input?

It can be achieved like this-

Code -

System.Text.RegularExpressions.Regex.Split(String.Join(",", inputDT.AsEnumerable.Select(Function (r) String.Join(",",r.ItemArray)).ToArray).Replace("F,", "~F,"), "~").skip(1).ToArray

output -

string[4] { "F,0,126,G,0,8125,K,0,0,K,0,0,G,0,8624,K,0,0,", "F,0,126,G,0,8125,K,0,0,K,0,0,G,0,8624,K,0,0,", "F,0,126,G,0,8125,K,0,0,G,0,8624,K,0,0,", "F,0,126,G,0,8125,K,0,0,G,0,8624,K,0,0" }

Thanks for the perfect solution to my question!
Unfortunately, I have only now seen thanks to your answer that there is another column in which an F stands.
Thus, regex unfortunately does not work. because I still need the later columns.

Here again the extended content of the table

Can not also refer only to the 1st column?
and can I not declare the datatype of the array as DT.
And where can I read this :slight_smile:

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