By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,939 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,939 IT Pros & Developers. It's quick & easy.

Using Array.FindAll

P: n/a
I'm using VB2005

I have an array of some 500,000 items which are of the form
080715_175327_312.jpg. These are camera frames of the form
YYMMDD_HHmmss_ms.jpg

I want to create another array which contains all the items which are (>
080715_1730) and (< 080716_0810)

What is the fastest way? I've found FindAll and IndexOf, but I can't work
out how to do it.

Thanks

-Jerry
Jul 29 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Jerry Spence1 wrote:
I'm using VB2005

I have an array of some 500,000 items which are of the form
080715_175327_312.jpg. These are camera frames of the form
YYMMDD_HHmmss_ms.jpg

I want to create another array which contains all the items which are (>
080715_1730) and (< 080716_0810)

What is the fastest way? I've found FindAll and IndexOf, but I can't work
out how to do it.

Thanks

-Jerry
Fortunately you have used an ISO 8601 like date format, which means that
the strings can be compared without having to parse each single value
into a DateTime value.

If the array is sorted, you can use the Array.BinarySearch method to
find the first and the last item. That would be very much faster than
looping through all the items.

If the array is not sorted, you have to loop. If you want to use the
FindAll method for that, you need a method like this to do the comparison:

Function Compare(value As String) As Boolean
Return value "080715_1730" And value < "080716_0810"
End Function

--
Göran Andersson
_____
http://www.guffa.com
Jul 30 '08 #2

P: n/a
Thanks Göran. It's the syntax of how to achieve this that I am struggling
with. The array is already sorted which helps. The Binary Search only seems
to produce values that are 'equals', rather than 'greater than ' AND 'less
than.'

-Jerry

"Göran Andersson" <gu***@guffa.comwrote in message
news:up**************@TK2MSFTNGP04.phx.gbl...
Jerry Spence1 wrote:
>I'm using VB2005

I have an array of some 500,000 items which are of the form
080715_175327_312.jpg. These are camera frames of the form
YYMMDD_HHmmss_ms.jpg

I want to create another array which contains all the items which are (>
080715_1730) and (< 080716_0810)

What is the fastest way? I've found FindAll and IndexOf, but I can't work
out how to do it.

Thanks

-Jerry

Fortunately you have used an ISO 8601 like date format, which means that
the strings can be compared without having to parse each single value into
a DateTime value.

If the array is sorted, you can use the Array.BinarySearch method to find
the first and the last item. That would be very much faster than looping
through all the items.

If the array is not sorted, you have to loop. If you want to use the
FindAll method for that, you need a method like this to do the comparison:

Function Compare(value As String) As Boolean
Return value "080715_1730" And value < "080716_0810"
End Function

--
Göran Andersson
_____
http://www.guffa.com

Jul 31 '08 #3

P: n/a
Jerry Spence1 wrote:
Thanks Göran. It's the syntax of how to achieve this that I am
struggling with. The array is already sorted which helps. The Binary
Search only seems to produce values that are 'equals', rather than
'greater than ' AND 'less than.'
If you look at the docs for BinarySearch, you'll find an overload which
allows you to specify your own function as the comparer.

The help for the Icomparer Interface shows how to implement that.

Andrew
Jul 31 '08 #4

P: n/a
Jerry Spence1 wrote:
Thanks Göran. It's the syntax of how to achieve this that I am struggling
with. The array is already sorted which helps. The Binary Search only seems
to produce values that are 'equals', rather than 'greater than ' AND 'less
than.'
The return value contains all the information that you need. If the
value was found you get the index of the item. If it was not found you
can get the index of the next item from the return value, then you know
that the item before it is less, and that item is greater.

--
Göran Andersson
_____
http://www.guffa.com
Aug 1 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.