|
-
Feb 17th, 2010, 10:27 PM
#1
Thread Starter
Member
Copy one dimensional array into two dimensional array?
I have a string containing many lines. Each line has many values separated by commas. Basically it's in CSV format. The number of lines is variable but the number of columns is always 7.
I can get each line into a one dimensional array using Split(Var, Chr(10)).
I'd like to make it a two dimensional array where the second dimension contains each comma separated value.
I've got
Code:
Dim VarArray1() As String = Split(VarText, Chr(10))
Dim VaryArray2(0 To VarArray1.Length - 1, 0 To 6) As String
Is there a quick way to get the contents of VarArray1 into VarArray2. I know I can do the following.
Code:
For Counter = 0 to VarArray1.Length - 1
Dim line as string = VarArray1(Counter)
Dim Values() as string = Split(line, ",")
For Counter2 = 0 to 6
VarArray2(Counter,Counter2) = Values(Counter2)
Next Counter2
Next Counter
But is there a quicker way to do it that doesn't require passing through each element of VarArray1 and then passing through each element of Values.
The eventual goal in all of this will be to find the highest value in the 3rd column (the arrays are strings at this point because not all columns are numeric). To do that once I get the values into VarArray2 I suspect I have to pass through each element VarArray2, i.e. VarArray2(Counter,2). Unless I can copy the whole third column into a SortedList?
-
Feb 17th, 2010, 10:37 PM
#2
Re: Copy one dimensional array into two dimensional array?
No, there is no quick way.
-
Feb 17th, 2010, 10:59 PM
#3
Thread Starter
Member
Re: Copy one dimensional array into two dimensional array?
Thanks for the response. I also have realized that a SortedList won't work because the values can be the same. I've decided to just pass through and put the column values into a one dimensional array and then use the Max property to find the highest. Pretty quick as it turns out.
-
Feb 17th, 2010, 11:05 PM
#4
Re: Copy one dimensional array into two dimensional array?
To be precise, Max is a method, not a property. To be more precise, it's an extension method added to support LINQ. That means that you call it like its a member of your list, e.g. myArray.Max(), but it's actually a member of the Enumerable module and your list gets passed in as an argument. To call it conventionally it would be Enumerable.Max(myArray).
-
Feb 17th, 2010, 11:16 PM
#5
Thread Starter
Member
Re: Copy one dimensional array into two dimensional array?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|