×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Appending arrays - HOWTO?

Appending arrays - HOWTO?

Appending arrays - HOWTO?

(OP)
Colleagues,
Can't recall if I've asked this Q. B 4, forgive me if I had. bowright

Say, you have two arrays of the same data type, and you need to add/concatenate/append them into one.
Besides the obvious (ReDim Preserve one array with the sum of elements and copy the elements of the second one to the empty sells of the first one) -
is there a function in the .NET that does exactly that? Something like (tried, dinna work)

CODE

Dim la1() As String = {"1", "2", "3"}
Dim la2() As String = {"4", "5", "6"}

Dim laS() As String = la1 & la2 ' Erred, "Error	BC30452	Operator '&' is not defined for types 'String()' and 'String()'" 

(I ran the search in MS .NET Help, found nothing helpful...)

Regards,

Ilya

RE: Appending arrays - HOWTO?

Have you tried something like this?

CODE

Dim la1() As String = {"1", "2", "3"}
Dim la2() As String = {"4", "5", "6"}
Dim laS() As String = la1.Concat(la2).ToArray() 

or

CODE

Dim la1() As String = {"1", "2", "3"}
Dim la2() As String = {"4", "5", "6"}
Dim laS(la1.Length + la2.Length - 1) As String
la1.CopyTo(laS, 0)
la2.CopyTo(laS, la1.Length) 

or

CODE

Dim la1() As String = {"1", "2", "3"}
Dim la2() As String = {"4", "5", "6"}
Dim laS(la1.Length + la2.Length - 1) As String
Array.Copy(la1, laS, la1.Length)
Array.Copy(la2, 0, laS, la1.Length, la2.Length) 

RE: Appending arrays - HOWTO?

(OP)
I like this Concat() the best! thanks2 , StrongM!

Actually, I need to concatenate 3 arrays, so I tried (C/C++ style, y'kno)

CODE

Dim la1() As String = {"1", "2", "3"}
Dim la2() As String = {"4", "5", "6"}
Dim la3() As String = {"7", "8", "9"}
Dim laS() As String = la3.Concat(la1.Concat(la2).ToArray()).ToArray() 

and it worked!

Regards,

Ilya

RE: Appending arrays - HOWTO?

Doesn't mikrom deserve some credit ponder

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Appending arrays - HOWTO?

(OP)
Forgot to click on star - mea culpa!
Done now.

Regards,

Ilya

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close