Working with Array Remove An Item

posted by Scudyen date: Thursday, May 22, 2008 category: ASP
  Featured Story | Printable View | Email It | Comments | Write Comment

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>


Happy Coding


Custom Search



Gazatem Technologies Active News Manager


page counter

Listed with 411asp.net
Listed with 4aspin.com
PHP, ASP, .NET, JSP Resources, Reviews