I have a 1 dimensional array, and I need to add it as a new line to a 2D array, how do I do this?
I actually have many 1D arrays, but I need to make them 1 2D array. Then later pull them back out into 1D arrays.
How do I do this?
Printable View
I have a 1 dimensional array, and I need to add it as a new line to a 2D array, how do I do this?
I actually have many 1D arrays, but I need to make them 1 2D array. Then later pull them back out into 1D arrays.
How do I do this?
Are they all (the 1D arrays) have the same demensions?
Must you use a 2D array? If you don't have to use a 2d array, you can use a List to hold the 1D arrays.
Quote:
Originally Posted by stanav
Well I'm importing lines of comma separated text from a file then parsing it to a 1D array. Each post parsed line arrays will be of the same length, yes. Each array line carries information pertaining to file, however I'll have many lines in to import (one for each file recorded), so I cant pre-define each 1D array, for it could be on the order of hundreds of 1D arrays, and the total number arrays will constantly be changing as the number of line entries in the imported document change.
How would I go about using a list?
Forget the array approach. Use a datatable. You can use ADO.Net to import a csv file to a datatable fairly easy. You can search this forum for code example of importing csv file to a datatable (search for something like "csv to datatable").
On the other hand, if you want to use a list you can do this:
Code:'Declare a list of string array
Dim myList As New List(Of String())
'Then when you read your csv file, after each line is converted to a
'string array, you add it to the list
'your code to open the file here... I don't want to rewrite it
line = reader.ReadLine()
'Split the line at the comma's into an array, then add it to the list
myList.Add(line.Split(","c))