I’m working on something relatively simple (or so I thought) and need a bit of help.
I am trying to create a dynamic amount of comma separated strings.
I have a variable (numberOfStrings) which is the number of different strings I need.
I just want to loop thru the aryDrivers and assign then to the different strings.
Dim aryHeats(numberOfStrings - 1) As ArrayList
Dim aryDrivers() As String
aryDrivers = txtBatch.Text.Split(",")
For i As Integer = 0 To aryDrivers.Length - 1
For j As Integer = 0 To aryHeats.Length - 1
aryHeats(j).Add(aryDrivers(i) & ",")
Next
Next
For some reason I’m getting an error in the loop when I try to “ADD” the string.
Thoughts?
Thanks!
** Update **
Maybe this will help explain more what I’m trying to do.
I have a string:
s = A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
i’m passing a variable (numberOfHeats) lets use 4.
i would like to then have 4 strings (so I am wanted to use array)
ary(0) = A,E,I,M,Q,U,Y
ary(1) = B,F,J,N,R,V,Z
ary(2) = C,G,K,O,S,W
ary(3) = D,H,L,P,T,X
hopefully that clears this up.
You could use LINQ, although i hate VB.NET method syntax:
Explanation: it takes the initial string and split it in words (comma as separator). Then it transforms the word and the according index in the String-Array to an anonymous type with
WordandIndexas properties. This list will be grouped byIndex Mod numberOfHeats(the number of arrays you want). This implicitely orders by your desired result. The last step is to transform the groups to a jagged array.Result: