• home
  • forum
  • my
  • kt
  • download
  • Working with Array : Remove An Item

    Author: 2007-06-24 21:11:03 From:

    Working with arrays could be painful if you could not remove any item after adding them in an array. Arrays are very helpful in programming languages, but in ASP it is not so easy.  VBScript does not contains strong functions to remove any item form your array list. Here there is a good ASP code block will be helpfull for your to remove and re-organized your array.



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>

    <title>Working with Array :  Remove An Item</title>
    </head>
    <body>
    <%
        ' First value must be FALSE
        ' Because we will try to search all items in array list
        removedItem = False
        Dim itemToRemove
        itemToRemove = "Some words to remove"
        arrayLength = UBound(myArray)

        for i = 0 to arrayLength
            if (myArray(i) = itemToRemove) then
                ' If we found our search term in array
                ' we are copying array to a new array list
                myArray(i) = myArray(arrayLength)
                ' So now our first value must be TRUE
                removedItem = True
            end if
        next

        if (removedItem = True) then
            ' Let's make a new array and pass all values
            redim preserve myArray(arrayLength - 1)
        end if   

    %>
    </body>
    </html>

    discuss this topic to forum

    relation tutorial

    No relevant information

    New

    Hot