Current location: Hot Scripts Forums » Programming Languages » Windows .NET Programming » How to remove an item from an array?


How to remove an item from an array?

Reply
  #1 (permalink)  
Old 04-06-07, 03:44 AM
ducthuan ducthuan is offline
New Member
 
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
How to remove an item from an array?

Hi, this question might be stupid for someone but that's all i want to ask for now.

Thanks.
Reply With Quote
  #2 (permalink)  
Old 04-10-07, 10:25 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Here is one way to do it:

Code:
Module Module1
    Sub Main()
        DoArrayResize()
    End Sub
    Sub DoArrayResize()
        Dim i As Integer = 0
        ' the original array has 10 items
        Dim a() As Integer = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
        ' lets say you want to remove element a(3) = 3
        For i = 3 To a.Length - 2
            a(i) = a(i + 1)
        Next
        a(a.Length - 1) = Nothing
        ReDim Preserve a(a.Length - 2)
    End Sub
End Module
__________________
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' Dr. Forensics PHP 3 07-15-06 03:54 PM
PHP - Unable to remove items from a file AdrianLewis PHP 5 03-17-06 05:14 AM
do something for each item in array except last one nassau PHP 4 01-14-06 12:46 PM
linking to iframe not working :( j0d JavaScript 5 01-19-04 08:14 PM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM


All times are GMT -5. The time now is 02:16 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.