LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Searching elements in array

How can I get all elements in a array that has a string subset?

For example:

[0] Apple
[1] Orange
[2] Bus
[3] Car
[4] Taxi
[5] Bike

Then, I look for "B"

It returns:
[2] Bus
[5] Bike

Someone could help me?

Thank you in advance.
0 Kudos
Message 1 of 6
(4,224 Views)
I would create an "helper array" that contains only the first character of each element, then use one of the algorithms in Darrens latest nugget (http://forums.ni.com/ni/board/message?board.id=170&message.id=209272) to search for certain elements.
 
Of course you would need to do this in a while loop until you run out of elements, similar to e.g. the following example:
 
Now index in the original array with the found indices. 
 
What is your LabVIEW version?
 
Of course you could also just loop through the original array and strip and compare each element indivdually. I really depends in the details of the applications what's best (how large are the arrays, how many different searches need to be performed, etc.)

Message Edited by altenbach on 10-10-2006 12:08 PM

0 Kudos
Message 2 of 6
(4,218 Views)
The array has 4000 elements and I would like to search for any subset of the elements.

The returned array must has the index of the elements that was found.

Any suggestions?

Thank you.


0 Kudos
Message 3 of 6
(4,212 Views)
If you have the time, I would suggest trying to follow Christian's advice.

However, here's a quick and dirty solution.  I'm no expert on efficiency, so I can't vouch for its speed with 4000 elements.

Just replace the "B" with whatever you're looking for.  I did not wire the "offset" input, so the default is 0 (first letter).  If you're looking for the 4th letter to be matched, change the offset input to 4, and change the equality check from 0 to 4.



Message Edited by Day on 10-10-2006 03:22 PM

Message 4 of 6
(4,209 Views)
Here's a simple example (LabVIEW 7.1).
 
(not that this lets you match any patterns, e.g. "pp" would return "Apple")
 
 

Message Edited by altenbach on 10-10-2006 12:39 PM

Message 5 of 6
(4,199 Views)
If you only want to match the first character, it would be quite efficient to only create an U8 index array, then search throught it. Here's an example (7.1).
Message 6 of 6
(4,188 Views)