Merging arrays

J

John

Hi

Is there a way to merge two or more single dimension string arrays into a
single, single dimension string array?

Thanks

Regards
 
L

Lloyd Sheen

John said:
Hi

Is there a way to merge two or more single dimension string arrays into a
single, single dimension string array?

Thanks

Regards

There is no "merge" functionality but you could just append the arrays and
the sort the array in the "merged" order.

Hope this helps.

Lloyd Sheen
 
C

Cor Ligthert [MVP]

Or in addition to lloyd merge as it is forever done by looping through the
two ore more files.

Be aware to make it first arraylist in both situations otherwise it will
probably freeze up your computer.

Cor
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

John said:
Hi

Is there a way to merge two or more single dimension string arrays into a
single, single dimension string array?

Thanks

Regards

Create a new array with the combined size of the arrays, and copy the
elements from the arrays:

Dim newArray As String() = New String(oldArray1.Length + oldArray2.Length)
oldArray1.CopyTo(newArray, 0)
oldArray2.CopyTo(newArray, oldArray1.Length)
 
M

Mattias Sjögren

Create a new array with the combined size of the arrays, and copy the
elements from the arrays:

Dim newArray As String() = New String(oldArray1.Length + oldArray2.Length)

I'm sure you meant

.... New String(oldArray1.Length + oldArray2.Length - 1) {}


Mattias
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Mattias said:
I'm sure you meant

... New String(oldArray1.Length + oldArray2.Length - 1) {}


Mattias

Yes. I don't program any VB myself nowadays. I thought that when
creating an array this way, it would use the size.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top