# Problem turning long string into 2D array

I have a problem turning a long string made up of lines of strings, each ending in a chr(13) into a 2-dimensional string array. There are 256 strings in the long string and the array will be (15,15) and the strings are entered in the right order ie the first 16 are row = 0, the next 16 are row = 1 etc. Is there a quick way to do this? I can’t quite get my head round it.

I forgot to mention that all the strings are 120 characters in length no including the chr(13) so maybe I can use that fact.

Have you tried splitting the strings into a 1D array and then looping through the 1D array counting the loops to add them to a 2 D array?

1 Like

Suppose, that you splitted all 256 strings into str256() array, like @Tom_Dixon mentioned
and then find the row and col for particular index.

``````Var str256(255) As String, row,col As Integer
//
Var row_height As Integer = 16
Var col_width As Integer = 16
//
For i As Integer = 0 To 255
str256(i) = i.ToString
row = i / row_height
col = i Mod col_width
Print( str256(i) + ",col="+col.ToString + ",row=" + row.ToString )
Next
//
// f-string from Python could be suitable for printing such expressions and not only ..
``````

Thanks Tom, for that suggestion, and thanks, Asian for your input, although I’ve been fiddling with it myself.
I had a routine indexGet that returns an index for r, c from 0 to 15 and eventually this did the trick, although I had to cut out the ch(13) characters and put in comma strings as separators.

``````dim a_temp() as string
a_temp = tFile.split(",")
a_Grid.ResizeTo(-1, -1)
a_Grid.ResizeTo(15, 15)
for r = 0 to 15
for c = 0 to 15
i = indexGet(r, c, 16)
a_Grid(r, c) = a_temp(i)
next
next

phew!
``````