Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Pulling items out of an Array

Posted on 2004-10-18
3
Medium Priority
?
260 Views
Last Modified: 2010-04-24
If I have MyArray(100) and wanted to pull out all elements that begin with a particular letter, how would that be done?  
0
Comment
Question by:Jedidia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 12340007
Here is one approach:

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private myArray() As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Put some test data in our array
        Dim temp As String
        temp = "cat,dog,elephant,cougar,crab,bear,fish,camel"
        myArray = Split(temp, ",")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim match As String
        Dim matches As ArrayList = getEntries("c")

        For Each match In matches
            ' do something with each match
            Debug.WriteLine(match)
        Next
    End Sub

    Private Function getEntries(ByVal beginningWith As String) As ArrayList
        Dim entries As ArrayList = New ArrayList
        Dim i As Integer

        For i = 0 To myArray.GetUpperBound(0)
            If myArray(i).StartsWith(beginningWith) Then
                entries.Add(myArray(i))
            End If
        Next i

        Return entries
    End Function

End Class
0
 
LVL 4

Expert Comment

by:gdexter
ID: 12340116
This Function will return an ArrayList containing the elements starting with the searchParam variable

    Private Function GetElements(ByVal searchParam As String) As ArrayList

        Dim i As Integer
        Dim al As New ArrayList

        For i = 0 To MyArray.GetUpperBound(0)
            If (CType(MyArray(i), String).StartsWith(searchParam)) Then
                al.Add(MyArray(i))
            End If
        Next

        Return al
    End Function
0
 
LVL 4

Expert Comment

by:gdexter
ID: 12340131
To late...
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question