Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: ArraySearch Binary Fast Search array Duplicate Multiple Values Option 1 3
strList = 'a a b c A A B C C 1 0 -1 -1' value = 'C' ; Create an array to search arrList = Arrayize (strList, ' ') ; Sort the array ArraySort (arrList) endsub = ArrInfo (arrList, 1) - 1 ; Search the array startsub = 0 result = 0 While @TRUE result = Arraysearch (arrList, value, 3, 0, startsub, endsub) If result == -1 Then Break Pause ('ArraySearch of value: ' : value, 'Element number: ' : result) startsub = result + 1 If startsub > endsub Then Break EndWhile ExitWhen using a binary search, there is a problem to find the small "c"? Is this a bug?
It makes more sense to just do a Linear search when you want to find every occurrence of a value unless you have a very large data set.
The following paragraph is taken from the ArraySearch functions documentation.
Duplicates
Fast Binary Search Options 1 & 3
Linear Search Options 0 & 2
This function will not necessarily locate the item with the lowest index of a set
of duplicates. To find every occurrence of a duplicate value, you must search in
both directions from the first found item. A linear search is the preferred method
to find every occurrence of a value, unless you have a very large data set.
This function can optionally search using a fast binary search but the array must
first be sorted on "search-column' using the ArraySort function.
A sequential search method for finding a value in an array. Checking each of its
elements in sequence, until the desired one is found. If your intent is to locate
all duplicate items then a linear search is recommended.
Article ID: W17658
Filename: ArraySearch Duplicate Values.txt
File Created: 2011:07:07:08:58:20
Last Updated: 2011:07:07:08:58:20