LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Delete ## and empty line from txt files

Solved!
Go to solution

Hi,

I have problem with my program.

I need to delete empy lines from my txt file.

 

This file is look like:

## Normalised capacitance data file
## Capacitance model: Parallel (K = 3.0)
## Created by: ECT32v2 for Win32 Beta2.25 (Jul 10 2003 01:54:24)
## Source: rec_flow_f45_v800_n2.bcp
##    Description: Contents of capture mode buffer
##    Date: 12:04:43 GMT Standard Time, 29Mar04
## Electrodes = 8, Measurements = 28
## Data for Plane 1


## frame 1 (0 msec)
0.006 -0.001 -0.004 -0.002 -0.028 -0.002 0.031 
-0.008 -0.005 -0.007 -0.024 0.005 0.004 
-0.014 -0.002 -0.011 -0.004 0.002 
-0.008 -0.003 0.004 -0.003 
-0.011 0.002 0.001 
0.004 0.005 
0.008 

## frame 2 (10 msec)
0.005 -0.002 -0.008 -0.002 0.006 0.011 0.023 
-0.008 -0.004 -0.004 -0.010 0.001 0.003 
-0.007 -0.001 -0.012 0.007 0.008 
-0.015 -0.004 0.002 0.001 
-0.007 -0.002 0.001 
0.008 -0.002 
0.005 

I want to delete all empty lines, lines which contain "##"

 

I try like attachment but it doesn't work.

 

How can I do this?

 

Regads,
Sorry for my english

 

0 Kudos
Message 1 of 10
(6,681 Views)

You need two tests. One for the empty lines and another for the lines starting with ##.

 

I converted the string to an array of strings. Then test each element of the array. Using conditional indexing, I build an output array of strings containing only the data elements. Then I convert that back to a single string.

 

Lynn

 

 

Message 2 of 10
(6,649 Views)

@piotrek0492 wrote:

Hi,

I have problem with my program.

I need to delete empy lines from my txt file.

 

This file is look like:

## Normalised capacitance data file
## Capacitance model: Parallel (K = 3.0)
## Created by: ECT32v2 for Win32 Beta2.25 (Jul 10 2003 01:54:24)
## Source: rec_flow_f45_v800_n2.bcp
##    Description: Contents of capture mode buffer
##    Date: 12:04:43 GMT Standard Time, 29Mar04
## Electrodes = 8, Measurements = 28
## Data for Plane 1


## frame 1 (0 msec)
0.006 -0.001 -0.004 -0.002 -0.028 -0.002 0.031 
-0.008 -0.005 -0.007 -0.024 0.005 0.004 
-0.014 -0.002 -0.011 -0.004 0.002 
-0.008 -0.003 0.004 -0.003 
-0.011 0.002 0.001 
0.004 0.005 
0.008 

## frame 2 (10 msec)
0.005 -0.002 -0.008 -0.002 0.006 0.011 0.023 
-0.008 -0.004 -0.004 -0.010 0.001 0.003 
-0.007 -0.001 -0.012 0.007 0.008 
-0.015 -0.004 0.002 0.001 
-0.007 -0.002 0.001 
0.008 -0.002 
0.005 

I want to delete all empty lines, lines which contain "##"

 

I try like attachment but it doesn't work.

 

How can I do this?

 

Regads,
Sorry for my english

 



Hello piotrek0492,

 

The lines that contains ## are not empty, so what would you like to do?

 

Michel

0 Kudos
Message 3 of 10
(6,644 Views)

@johnsold wrote:

You need two tests. One for the empty lines and another for the lines starting with ##.

 

 


This will work but not necessarily for just lines starting with ## but also if ## appear in between (very unlikely given the file format). If that is a possibility, you have to use a regex.

^ will ensire it is checked at the beginning.

 

regex.png


CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
Message 4 of 10
(6,628 Views)

First of all, please do us the courtesy of submitting executable code (attaching a VI is the easiest way to do this) so that we don't have to recreate your program ourselves to test it.

 

Have you taken the freely-available LabVIEW tutorials and spend a few hours learning the basics of LabVIEW?  Have you programmed up the example code in the Tutorials for yourself and tried making small changes to get it to do other things?

 

Sometimes it is helpful to think about the problem before jumping into coding.  Here's how I see your task:

  • The input is a text file, with text being given in lines
  • The output will be another text file consisting of some of the lines of the input
  • Lines that start with "##" will not be part of the output
  • Lines that are blank will not be part of the output
  • All other lines will be part of the output

Do you see any "logical structure" to this description?  Are there obvious loops, obvious "branch" decision points?  What LabVIEW constructs handle loops?  How do you read lines of text?  How do you selectively output lines of text?

 

Bob Schor

0 Kudos
Message 5 of 10
(6,604 Views)

Good advise has already been provided.

But just for fun here is a couple of loops that will perform parsing functions that may work depending on your desired outcome.

Yes there are other ways but you can trace through the code maybe pick up something along the way.

 

Good luck

Message 6 of 10
(6,590 Views)

For the fun of it I tried to get a solution without loops.

 

Ben64

 

delete from string.png

Message 7 of 10
(6,542 Views)
Solution
Accepted by piotrek0492

Ben thanks for the example. Somehow I had missed the setting that allowed the expresion search. Your example sent me back to the help files to figure it out. I have modified my first code to show the method I hope  I have the explaination correct. Not trying to do someones homework for them but for those who need a quick start perhaps this will help someone else along the way.

Message 8 of 10
(6,487 Views)

A little difference with my method is that it also remove the space and the line feed after the final 0.005 value.

 

Ben64

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

thanks for all the answers.
It helped me in solving tasks and accede to the further stages of the work.

Regards

0 Kudos
Message 10 of 10
(6,470 Views)