LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

remove empty string from array

I am producing data into a one dimensional array of strings that looks like
 123
empty string
empty string
empty string
124
empty string
empty string
empty string
123
etc.
 
What is the easiest way of removing these empty strings?
 
Alternatively is it possible to outpul NULL from a case statement rather than an empty string?
 
 
 
0 Kudos
Message 1 of 10
(6,591 Views)

If the pattern is regular, you could reshape the array into a 4 x N/4 array and take the first column/row.

If the pattern is irregular, you could built a new array in a loop. (Most likely you can modify this for direct use in your code and built the array only with good elements from the beginning).

The attached shows both possibilities. (LabVIEW 7.0)

(If the array is very large, there are a few tweaks to make it more memory efficient, but the above should get you started)

Message Edited by altenbach on 03-01-2006 08:33 PM

Message 2 of 10
(6,583 Views)


@beccccc wrote:
 
... Alternatively is it possible to outpul NULL from a case statement rather than an empty string?


It sounds like individual strings are being produced in the code - from inside a for-loop (or while loop)?

If the problem is that some loop is generating an element every iteration, but there isn't data every iteration, then you, may be interested in the "Shift Register".(see example)

Cheers.

 

When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 3 of 10
(6,576 Views)

Thanks guys, The first solution is working quite well, but I will explain how I came up with the problem for further clarification.

I have saved data into a text file which is in the format:  channelNo-Data\n    so..

0001-1234

0002-1233

0003-1222

0001-1235

0002-1372

etc.

I am then seperating the channelNo and the Data out of the string

Running it through a case statment as a way of sorting the data into channels.

The problem I found with my case statement was that when the channelNO isn't equal for the channel number I am looking for then you need to output some data.

This is all inside a for loop to build an array of numbers which when i use "empty string" for a false case outputs an array which contains data followed by a series of string elements which are empty.

 

 

 

0 Kudos
Message 4 of 10
(6,576 Views)
Why don't you attach a simplified version of your code so we can better help you find the best solution? 🙂
0 Kudos
Message 5 of 10
(6,569 Views)
Here is a simplifed version of where I how I am reading in the txt document at the momment, and a copy of an example txt file for reading.
Download All
0 Kudos
Message 6 of 10
(6,565 Views)
Well, you can just built the string array in the main loop as in the attached quick modification of your VI.
 
Make sure to initialize your shift register. Also, you definitely don't need a shift register for the file name.
 
"Read lines from file" is OK for small very files but a poor choice for larger files because it opens and closes the file for each line. This creates a lot of overhead. You should read the entire file at once, then operate on the string to grab the lines.
0 Kudos
Message 7 of 10
(6,551 Views)

Hi beccccc,

      Thanks for the example of your code - glad you asked, Altenbach Smiley Wink

Here are some more ways to extract the channel data.  Like Altenbach said early-on, "if the pattern is regular" ...

Cheers

Message Edited by Dynamik on 03-02-2006 03:01 AM

When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 8 of 10
(6,546 Views)

Hi Dynamik ,

I am using labview 7.0, so I can't see the code you produced, could you attach it as a jpg?

 

Becccc

 

0 Kudos
Message 9 of 10
(6,515 Views)

Hi becccc,

      This is the core code in 7.0.  When saving to previous version, 7.1 complained about some of the other diagram objects, so they are omitted.

When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 10 of 10
(6,492 Views)