0

我有一个数组。我遍历它并显示值。显示后,我想删除该特定节点以减小数组大小。

例子

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

请帮忙。

4

1 回答 1

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
于 2013-09-05T10:53:43.280 回答