LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Clone an array element a varying number of times

Hello,

 

I am trying to make a vi file that does the following:

1. It accepts a string as an input. The string contains a series of concatenated commands.

2. It finds a command of the type repeat 2 <xxx>

3. It replaces "repeat 2 <xxx>" with "xxx xxx" (e.g. repeat 3 <xxx> would become "xxx xxx xxx"). The markers < and > can be substituted with a different symbol (e.g. [], {}, ()).

4. This happens for all the instances of repeat commands within the string, so that in the end a new string is produced that does not contain any repeat commands.

repeat.png

I attach a screenshot of the program so far, as well as the program itself.

 

I cannot figure out how to use the regular expressions properly. "Repeat [0-9]" does not capture the entire command. I would like to have something like "Repeat [0-9] <*>" where * can be anything, but I cannot figure out how to write this using the regular expressions.

 

Also, is there an elegant way to do what I want using the search and replace string vi?

 

Any help would be greatly appreciated.

0 Kudos
Message 1 of 8
(4,781 Views)

@edu11 wrote:

 

... so that in the end a new string is produced that does not contain any repeat commands.

 


Why not just remove all the lines that contain the word "repeat"?

 

(Alternatively, you could just edit each matching line by replacing each word with "xxx", which would not be much more complicated starting with the given code)

 

(Do you know that you can change the mode of the termination condition of a while loop so you don't need to "not" the value?)

Message 2 of 8
(4,750 Views)

Hi altenbach,

 

I did not express myself correctly. The objective is not to merely remove the lines containing "repeat" but substitute them with the command in the brackets. The command in the brackets will be duplicated as many times as dictated by the number next to "repeat".

 

So, repeat 2 {xxx} will become xxx xxx because the number next to repeat is 2.

Repeat 4 {y} will become y y y y and so on...

 

Also, ideally I would like more than one command in the brackets e.g.

 

repeat 2 {command 1

command 2},

with the result being:

command 1

command 2

command 1

command 2

 

As you can guess, this is all about designing a new command.

0 Kudos
Message 3 of 8
(4,731 Views)

Ah, I took the "xxx" literal. I guess you just want to unroll the "repeat" loops.

 

So you just need to use an inner case structure and FOR loop after finding the lines with the word "repeat", that append N instances of the string. Try it.

Message 4 of 8
(4,726 Views)

I tried but I have a problem with how to extract the string between the brackets (the commands that need to be cloned).

repeat_MODCA2.png

 

 

0 Kudos
Message 5 of 8
(4,688 Views)

I'm close but the concatenation has me perplexed.

repeat_MODCA3.png

0 Kudos
Message 6 of 8
(4,679 Views)

And this is my latest attempt. Somehow it still doesn't work.

repeat_MODCA4.png

0 Kudos
Message 7 of 8
(4,665 Views)

Since you want to keep data from both cases, get rid of the conditional tunnel and use a plain indexing tunnel. Also your shift register definitely needs to be initialized, else it remembers all previous data from the same session. This still looks buggier than a formicarium. 😄

 

Here's a quick attempt, but I am sure it could be improved. You need to ensure that it correctly deals with malformed inputs and such. This is just a very rough draft and probably has bugs and oversights. I am not quite sure what needs to be escaped in the regex.

Message 8 of 8
(4,661 Views)