Posted By

Scooter on 01/10/09


Tagged

arrays


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

wizard04


Array Merge


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2009/01/array-merge.html

  1. <%
  2. ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
  3. '
  4. ' This work is licensed under the Creative Commons Attribution License. To view
  5. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  6. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  7. ' 94305, USA.
  8.  
  9. ' Merge two arrays into one.
  10. function array_merge(byVal firstArray, byVal secondArray)
  11. dim totalSize
  12. dim i
  13. dim combinedArray
  14.  
  15. ' Ensure that we're dealing with arrays.
  16. if not isArray(firstArray) then
  17. firstArray = Array(firstArray)
  18. end if
  19.  
  20. if not isArray(secondArray) then
  21. secondArray = Array(secondArray)
  22. end if
  23.  
  24. ' Set up the new array.
  25. totalSize = uBound(firstArray) + uBound(secondArray) + 1
  26. combinedArray = firstArray
  27. redim preserve combinedArray(totalSize)
  28.  
  29. for i = 0 to uBound(secondArray)
  30. combinedArray(uBound(firstArray) + 1 + i) = secondArray(i)
  31. next
  32.  
  33. array_merge = combinedArray
  34. end function
  35. %>

Report this snippet  

You need to login to post a comment.