LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Extract all elements containing one string and the element before it from 1d array

Hi, I am trying to write a simple program that extracts all elements containing a given element (the element to extract will be hardcoded) and the element before it. I have attached a screenshot containing example input and output. In this example code, the elements I want to extract are all elements containing 'A'. My data will be structured that all desired elements (in this case 'A') will be squeezed between unwanted elements (in this case C, D and E), but the desired element can also be in the first index. Does anybody know how to implement this in an easy way?

Asasafuchi_0-1747807553285.png

 

0 Kudos
Message 1 of 10
(592 Views)

Hi Asasa,

 


@Asasafuchi wrote:

Hi, I am trying to write a simple program that extracts all elements containing a given element (the element to extract will be hardcoded) and the element before it. I have attached a screenshot containing example input and output. In this example code, the elements I want to extract are all elements containing 'A'. My data will be structured that all desired elements (in this case 'A') will be squeezed between unwanted elements (in this case C, D and E), but the desired element can also be in the first index. Does anybody know how to implement this in an easy way?


Why do you request for an "easy" way? Why not ask for generic suggestions?

 

Your requirement isn't well-defined!

You want to read the "given element and the element before it": in your example there are three consecutive "A" elements - according to your requirement you should result in 5 consecutive "A" elements (with an "E" in front) in the output array!!!

 

So please write down the requirement WITH ALL considerations/"border effects"!

 

What have you tried so far?

Where are you stuck?

Best regards,
GerdW


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

Going by your picture: Instead of looking at the element before, look at the next one. If either the current or next element is an A, keep the current element.

0 Kudos
Message 3 of 10
(554 Views)

From your picture, B is the first element and the resulting array is with B removed. Is that what you're after?

Yamaeda_0-1747838765607.png

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 10
(526 Views)

My understanding is to remove every element that is not A AND not followed by an A..

 

forum regex.png

ben64_0-1747841655848.png

Ben

0 Kudos
Message 5 of 10
(519 Views)

Are all strings guaranteed to be single characters?

0 Kudos
Message 6 of 10
(510 Views)

no, but the strings that I want to extract will be identical and they can be hardcoded as they will always be the same. 

0 Kudos
Message 7 of 10
(476 Views)

Hi, yes almost. 

 

the goal is to extract all strings containing a given element, in this case A. and the two adjacent elements that are NOT A.

 

I have implemented something that I think works. It is pretty messy so if anybody has some suggestions on an easier way to implement this I would be happy to see it. 

 

 

 

 

0 Kudos
Message 8 of 10
(450 Views)

Hi Asasa,

 


@Asasafuchi wrote:

the goal is to extract all strings containing a given element, in this case A.

and the two adjacent elements that are NOT A.


In your first message you gave as input:

  BCAAADABEAAA.

The desired result was given as:

  CAAADAEAAA

 

When you want "A and two adjacent elements" then why is there no "B" in the output???

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 10
(441 Views)

I think the title gives it away.  The character "B" is never followed by the Character "A" in the string sequence given; therefore, B is never present in the output.  

 

Now the title is different from the instructions that you have provided later - Please Clarify. What is the actual requirement?

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
0 Kudos
Message 10 of 10
(420 Views)