VB array search-function

WizardOz

Member
Licensed User
Longtime User
Hi!

I need to check a string (a) with an array of strings, the results is the array'ed strings that contains string (a)...

VB6 had a function for searching an string-array that was pretty fast, even with a large array:
Filter(InputStrings, Value[, Include[, Compare]])

Info about the function: VBScript Filter Function

The only way I have found to search an array in B4A is to travel through every string in the array by "hand" to deliver the same results, causing quite a delay on a big array.

Is there a lib or something similar that can do this lightningfast as the VB-function? :sign0163:
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use a List instead. You can then use List.IndexOf to search for an item. However this will not be faster then searching for it manually (in both cases it will probably be exactly the same speed as the VB function) - O(n) complexity.

You should use a Map instead. You can check if a key exists very fast ~ O(1) complexity.
 
Upvote 0

WizardOz

Member
Licensed User
Longtime User
Good pointers Erel, as usual :)

But my "problem" is that not only am I searching for the excact match, I am looking for if the list/array contains the searchstring...
Example:
Search: TRO
Array(1) = TROY
Array(2) = SOMETHING
Array(2045) = OTROIAN
Array(4067) = ELSE

The VB-function would give me Array(1) and Array (2045) quite fast.
Manual running trough the array takes some time, so I was after a faster function that probably dont exist.
I guess a map is out of the question, since its not only the exact match I am after...

Oh well, thanx for the tips anyway :)
 
Upvote 0
Top