VBOfficer Posted March 13, 2009 Posted March 13, 2009 (edited) Hi, I have 2 arrays, I don't know their length... I wanna copy both arrays into 1 single array. So the length of output array will be sum of my 2 input arrays. I know I should use Array.Copy but don't know how, for my case, it won't merge the contents of 2 arrays into 1. Anyone can help me? I also used this but won't work: ReDim OutputArray(InputArray1.Length + InputArray2.Length - 1) Array.Copy(InputArray1, OutputArray, InputArray1.Length) Array.Copy(InputArray2, OutputArray, InputArray2.Length) Thanks :) Edited March 13, 2009 by VBOfficer Quote
Leaders snarfblam Posted March 13, 2009 Leaders Posted March 13, 2009 You need to specify where to begin copying to when calling Array.Copy using a different overload (at least with InputArray2, since you don't want to copy that to the beginning of OutputArray). ReDim OutputArray(InputArray1.Length + InputArray2.Length - 1) ' Parameters are sourceArray, sourceOffset, destArray, destOffset, length) Array.Copy(InputArray1, 0, OutputArray, 0, InputArray1.Length) Array.Copy(InputArray2, 0, OutputArray, InputArray1.Length, InputArray2.Length) In the last line, the code specifies to copy InputArray2 starting where InputArray1 left off (the second to last parameter). Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.