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

T

Trint Smith

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
(e-mail address removed)
 
F

Fergus Cooney

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
alTheGroup.Add (asTheArray(I))
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
 
S

SmartiKat

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top