LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting a specified string from 1D array of strings

Solved!
Go to solution
Highlighted

I have created a VI that creates 1d array of strings of available VISA resources. I can separate these with index selector but the problem is that VISA resource could possibly be at any index location. Can I choose certain index that starts with certain pre-defined text?

 

For example if I have 2 index and index I want to choose starts with "USB.." and other(s) does not, how can I allways choose the one that starts with "USB.." 

0 Kudos
Message 1 of 10
(381 Views)
Highlighted

Use a FOR loop to iterate through your strings and stop the loop early when you find an element that matches your criteria.  Or if you are just using an exact string match use Search 1D Array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 2 of 10
(377 Views)
Highlighted

What function should I use to find correct index when using FOR loop? It is not an exact match so Search 1D Array is no good. I didn't find anything suitable for comparison functions also?

0 Kudos
Message 3 of 10
(364 Views)
Highlighted

Hi LWnew,

 


@LWnew wrote:

What function should I use to find correct index when using FOR loop?


Did you note this little "i" item inside the loop, which tells you the number of the current iteration?

 


@LWnew wrote:

I didn't find anything suitable for comparison functions also?


When you want to parse strings then you should use a string function. MatchPattern might work for you…

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
0 Kudos
Message 4 of 10
(357 Views)
Highlighted

Hi,

 

Here is an example for my current found VISA resources. 

 

Capture.PNG

 

Program has found 2 VISA resources. I want to choose full USB one, but the problem is that it could be in any index. Match pattern divided my string in 3 parts. If I use USB as regular expression it divides USB to "match substring"

 

Capture.PNG

 

Here is also the program that I use for testing this.

Download All
0 Kudos
Message 5 of 10
(343 Views)
Highlighted

@LWnew wrote:

What function should I use to find correct index when using FOR loop?


Do you care about the index or just the actual value?  If you just want the index, then wire the i out of the loop.  If you really just want the value, then wire the value out of the loop (do not index the output tunnel and you will get the last value).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 6 of 10
(341 Views)
Highlighted
Solution
Accepted by LWnew

@LWnew wrote:

Program has found 2 VISA resources. I want to choose full USB one, but the problem is that it could be in any index. Match pattern divided my string in 3 parts. If I use USB as regular expression it divides USB to "match substring"

 

Capture.PNG


Give this a try.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 7 of 10
(336 Views)
Highlighted

@crossrulz wrote:

@LWnew wrote:

Program has found 2 VISA resources. I want to choose full USB one, but the problem is that it could be in any index. Match pattern divided my string in 3 parts. If I use USB as regular expression it divides USB to "match substring"

 

Capture.PNG


Give this a try.


Same as above (Except using a conditional terminal on the for loop)

FindUSB.png

Message 8 of 10
(301 Views)
Highlighted

Both seem to be working. Thanks all.

0 Kudos
Message 9 of 10
(290 Views)
Highlighted

@adekruif wrote:

Same as above (Except using a conditional terminal on the for loop)

FindUSB.png


Good call!  I will state that is is not uncommon for me to pass the conditional value out so I can generate an error if the element was not found.  You just fixed an old habit of mine (I've been doing these types of searches since the conditional terminal was added to the FOR loop in LabVIEW 8.6, the tunnel conditional was added much later).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 10 of 10
(288 Views)