繁体   English   中英

在经典ASP中动态减小数组大小

[英]Dynamically reduce the array size in classic ASP

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

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

请帮忙。

您可以使用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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM