SplitTo2DArray

Split up the table value (String with separators) by rows and by columns into 2D array.
Works also in VBA


Public

Tested

My Own Work
Function SplitTo2DArray(the_sValue, the_sRowSep, the_sColSep, toArray)
Dim vasValue
Dim nUBoundValue
Dim avasCells()
Dim nRowIndex
Dim nMaxUBoundCells
Dim nUBoundCells
Dim asCells()
Dim nColumnIndex
' Split up the table value by rows, get the number of rows, and dim a new array of Variants.
vasValue = Split(the_sValue, the_sRowSep)
nUBoundValue = UBound(vasValue)
ReDim avasCells(nUBoundValue)
' Iterate through each row, and split it into columns. Find the maximum number of columns.
nMaxUBoundCells = 0
For nRowIndex = 0 To nUBoundValue
avasCells(nRowIndex) = Split(vasValue(nRowIndex), the_sColSep)
nUBoundCells = UBound(avasCells(nRowIndex))
If nUBoundCells > nMaxUBoundCells Then nMaxUBoundCells = nUBoundCells
Next
' Create a 2D string array to contain the data in .
ReDim asCells(nUBoundValue, nMaxUBoundCells)
' Copy all the data from avasCells() to asCells().
For nRowIndex = 0 To nUBoundValue
For nColumnIndex = 0 To UBound(avasCells(nRowIndex))
asCells(nRowIndex, nColumnIndex) = avasCells(nRowIndex)(nColumnIndex)
Next
Next
toArray = asCells
End Function

the_sValue, the_sRowSep, the_sColSep, toArray

Views 3862 Downloads 1256

Classic ASP Texts + Strings
ANmarAmdeen
813
Revisions

v1.0