LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search multiple matches from a string in to array

Hello,

 

I am trying to search multiple matches from a string.

The Search/Split or Match Pattern only finds the first match but is it possible to create an array of matches for example?

The match im searching contains multiple versions and I am trying to create an array of them.

Can anybody help me out?

Versionsearch.png

0 Kudos
Message 1 of 6
(3,497 Views)

Hi Teba,

 

basic stuff:

When you want to repeat the very same operation multiple times, you should use a loop.

When you know the number of iterations in advance you should use a FOR loop, otherwise a WHILE loop…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(3,489 Views)

Hi GerdW,

 

Thanks for the quick reply but the loop just keeps searching the same first version when im trying to build an array of all the versions from the response string. Picture below:

Versionsearch2.png

0 Kudos
Message 3 of 6
(3,482 Views)

You need to use a shift register.  You initialize it with the full constant.  Then inside the loop, you refresh it with the "After Match" string, so the next iteration it can search for the next match.

0 Kudos
Message 4 of 6
(3,457 Views)

Yes you are finding the same string every time because you never remove that first line from the search. 

 

You have lots of option as to how to fix this:

 

1) convert your input string to an array (look up Spreadsheet String to Array in the String Pallette) before you enter the for loop and use auto-indexing to feed the loop each array item (No need to wire N itterations with auto-indexing).

 

2) use a shift register and wire the remainder after match to the shift register to be used for the next loop.  If you use a shift register you need some logic to get the loop to stop when all matches are found.  (Hint: while loops or For loop with conditional termination enabled.)

 

3) a shift register that keep track of the oftset position of the match after every loop and feeds it back into the next loop. 

 

Options 1 and 2 are easier, but it really depends on how your real input is formatted.  If there's always a \n then 

 

Craig 

 

 

0 Kudos
Message 5 of 6
(3,455 Views)

Hi Teba,

better suitable is "Match Pattern" and the input "Offset" in combination with "Offset past Match".

 

Match Pattern.png

 

Greets, Dave
Message 6 of 6
(3,454 Views)