在ASP(Active Server Pages)中,可以使用以下方法之一來復制數組:
方法1:使用Array.Copy()
方法
<%
Dim originalArray(5) As String
originalArray(0) = "A"
originalArray(1) = "B"
originalArray(2) = "C"
originalArray(3) = "D"
originalArray(4) = "E"
originalArray(5) = "F"
Dim newArray(5) As String
Array.Copy(originalArray, newArray, originalArray.Length)
' newArray 現在是原始數組的副本
Response.Write("Original Array: " & Join(", ", originalArray))
Response.Write("<br />New Array: " & Join(", ", newArray))
%>
方法2:使用循環遍歷數組并逐個復制元素
<%
Dim originalArray(5) As String
originalArray(0) = "A"
originalArray(1) = "B"
originalArray(2) = "C"
originalArray(3) = "D"
originalArray(4) = "E"
originalArray(5) = "F"
Dim newArray(5) As String
Dim i As Integer
For i = 0 To UBound(originalArray)
newArray(i) = originalArray(i)
Next
' newArray 現在是原始數組的副本
Response.Write("Original Array: " & Join(", ", originalArray))
Response.Write("<br />New Array: " & Join(", ", newArray))
%>
方法3:使用Array.Clone()
方法
<%
Dim originalArray(5) As String
originalArray(0) = "A"
originalArray(1) = "B"
originalArray(2) = "C"
originalArray(3) = "D"
originalArray(4) = "E"
originalArray(5) = "F"
Dim newArray As String() = CType(originalArray.Clone(), String())
' newArray 現在是原始數組的副本
Response.Write("Original Array: " & Join(", ", originalArray))
Response.Write("<br />New Array: " & Join(", ", newArray))
%>
以上三種方法都可以用于復制ASP數組。你可以根據自己的需求和喜好選擇合適的方法。