在ASP中,可以使用Array.Append
方法或Array.Combine
方法来合并数组。以下是两种方法的示例:
方法1:使用Array.Append
<%
Dim arr1(2)
arr1(0) = "A"
arr1(1) = "B"
arr1(2) = "C"
Dim arr2(2)
arr2(0) = "D"
arr2(1) = "E"
arr2(2) = "F"
' 合并数组
Dim arrResult()
ReDim Preserve arrResult(UBound(arr1) + UBound(arr2))
For i = 0 To UBound(arr1)
arrResult(i) = arr1(i)
Next
For i = 0 To UBound(arr2)
arrResult(UBound(arr1) + i) = arr2(i)
Next
' 输出合并后的数组
Response.Write "合并后的数组: " & Join(", ", arrResult)
%>
方法2:使用Array.Combine
<%
Dim arr1(2)
arr1(0) = "A"
arr1(1) = "B"
arr1(2) = "C"
Dim arr2(2)
arr2(0) = "D"
arr2(1) = "E"
arr2(2) = "F"
' 合并数组
Dim arrResult()
ReDim Preserve arrResult(UBound(arr1) + UBound(arr2))
For i = 0 To UBound(arr1)
arrResult(i) = arr1(i)
Next
For i = 0 To UBound(arr2)
arrResult(i + UBound(arr1) + 1) = arr2(i)
Next
' 输出合并后的数组
Response.Write "合并后的数组: " & Join(", ", arrResult)
%>
这两种方法都可以实现数组的合并。Array.Append
方法将一个数组的元素逐个添加到另一个数组的末尾,而Array.Combine
方法将两个数组的元素按顺序组合成一个新的数组。注意,在使用ReDim Preserve
时,要确保新数组的大小足够容纳合并后的所有元素,以避免数组越界错误。