我有一个数组。我遍历它并显示值。一旦显示,我想删除该特定节点,以便减少数组大小。
实施例
tot = 20
redim values(tot)
for i=1 to 20
values(i) = i
next
for i=1 to ubound(values)
if values(i) = 10 then
' i do my work here.
' After my work is done, i want to remove the node values(10)
' so that the ubound of my array changes to 19 and not 20
' when i loop through next time.
end if
next
请帮忙。
答案 0 :(得分:1)
您可以使用Redim Preserve
更改数组的大小并保留值要删除节点,您可以尝试:
tot = 19
redim values(tot)
for i=0 to UBound(values)
values(i) = i+1
next
Response.write "Initial Size:"& UBound(values) & "<br/>"
bMoveUp = false
for i=0 to ubound(values)
if values(i) = 10 then
'do your thing with the i=10 the element
bMoveUp = true
end if
if bMoveUp = true Then
if i <> ubound(values) then
values(i) = values(i+1)
end if
End If
next
Redim Preserve Values(ubound(values)-1)
Response.write "Final Size:"& UBound(values) & "<br/>"
for i=0 to UBound(Values)
Response.write values(i) & "<br/>"
next