472,110 Members | 2,215 Online

# how can i find all instances of a number in an array??

how can i find all instances of:
'number' in the array??
there will always be 7 instances of the same number. like:
030828700Program.txt
030828700BatchGroup.txt
030828700Group.txt
030828700Item.txt
030828700Seller.txt
030828700ItemsSold.txt
030828700Image.txt
thanks,
Trint

..Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
2 1680
Hi Trint,

I've got two methods for you:

[1]
Dim sGroupNumber As String = "030428700"
Dim alTheGroup As ArrayList
Dim I As Integer

For I = 0 To asTheArray.Length - 1
If asTheArray(I).StartsWith (sGroupNumber) Then
End If
Next

'alTheGroup now contains the items for "030428700".

Or:

[2]
'Get all the groups together.
Array.Sort (asTheArray)

'Find the first item in the group that I want.
For I = 0 To asTheArray.Length - 1
If asTheArray(I).StartsWith (sGroupNumber) Then
Exit For
End If
Next

'Did I find the group?
If I < asTheArray.Length Then
'Yes.
'asTheArray(I) and the following six items have the items
for "030428700".
'In order of name: BatchGroup, Group, Image, Item,
ItemsSold, Program
: : :
End If

Method [2] obviously doesn't need the Sort if your list is already
sorted.

Regards,
Fergus

Nov 20 '05 #2
Hey Trint,

You are not even trying... 3 options:
1) Look up .Startwith
2) Loop it and use instr

I highly recommend you start writing out your problem on a piece of paper
and try to solve it with Psuedo-Code. To be a successful programmer, you
really need to "THINK", "TRY", and "READ THE MANUAL".

A

"Trint Smith" <tr********@hotmail.com> wrote in message
news:Om**************@TK2MSFTNGP09.phx.gbl...
how can i find all instances of:
'number' in the array??
there will always be 7 instances of the same number. like:
030828700Program.txt
030828700BatchGroup.txt
030828700Group.txt
030828700Item.txt
030828700Seller.txt
030828700ItemsSold.txt
030828700Image.txt
thanks,
Trint

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #3

### This discussion thread is closed

Replies have been disabled for this discussion.