LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete an element from an array that doesn't start with a certain string?

See attached VI. I want to delete the elements from this array that don't start with OB1. How do I do this?

0 Kudos
Message 1 of 6
(2,468 Views)

Note that the Example String you provided has no lines starting with "OB1"!

 

You have a multi-line string.  The first thing you want to do is to convert it to an Array of Strings.  This is not a difficult function to write, but it's even easier to use the "String to 1D Array" function from the OpenG String functions available on the LabVIEW Tools Network (accessed with VIPM, the VI Package Manager, which should have been installed with LabVIEW, but otherwise is a free download from JKI.net) (go ahead and install the OpenG Toolkit, which gives you additional Useful Functions that NI is gradually (over >12 years) adding to LabVIEW).

 

Now you can pass the Array into a For loop, which allows you to test each element one at a time and get "True" (meets your Criterion) or "False" (fails to meet your Criterion).  Bring this to the output Indexing Tunnel, and assuming you are using a version of LabVIEW less than 6 years old, right-click on the Tunnel, add the Conditional qualifier, and wire the output of the Test to the "?" terminal.  Your output Array will be just what you want, those elements where the test was True (or an Empty Array if none of them match).

 

Bob Schor

 

0 Kudos
Message 2 of 6
(2,447 Views)

Well, you almost have it!

 

You already succeeded in splitting the string and removing the first parts of it. The only mistake now is that you check on the first three characters is outside of the for-loop. You should do the comparison inside the for-loop, store all the correct ones in a new array and wire this to the loop output.

0 Kudos
Message 3 of 6
(2,436 Views)

Something like this:

 

Example.png

Tim
GHSP
0 Kudos
Message 4 of 6
(2,429 Views)

Regexes

 

regexes.png

 

Ben64

0 Kudos
Message 5 of 6
(2,416 Views)

Here's another possibility. (not really clear what output you need).

 

FilterEntries.png

0 Kudos
Message 6 of 6
(2,369 Views)