Example Code

Search 1D String Array Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This VI is for finding and returning matches to a search string within a 1d string array and the respective indices of the results.

 

Description

This VI makes use of the search/split string function to find matches of a search term in a string array. For example, if you have an array with the following elements:

 

Element1, Element2, Element3 

 

You could search for Element to return an array of both the results Element1, Element2, Element 3 and their indices 0, 1 and 2. The input array and search term terminals accept a 1d array of strings and an individual string respectively. The match indices and match values outputs return 1d arrays of long integers and strings respectively.

 

Requirements

  • LabVIEW 2012 (or compatible)

  

Steps to Implement or Execute Code

  1. Input the search term to be searched in the input array
  2. Input the string array
  3. Run VI
  4. Match Indices and Match Values show the result corresponding to each element of the Input array

 

Additional Information or References

VI Snippet

1D String.png

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

Matt H
Applications Engineer
National Instruments UK

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
crossrulz
Knight of NI Knight of NI
Knight of NI
on

Why didn't you just use the Auto Indexing on the FOR loop for the Input Array.  That would eliminate the need to use Array Size wired to N and the need to index the value inside the loop.

Here's how I would clean up this VI.

Search String Array.png


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
MHutch
NI Employee (retired)
on

Thank you for the feedback crossrulz, I will have a look and incorporate changes. The VI itself was adapted from a larger project in which it was a recursive VI instead, which will explain why some of the code might seem strange or out of place. But thank you for your suggestions!

Matt H
Applications Engineer
National Instruments UK