LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Remove last comma before reading csv files

Solved!
Go to solution

Hello,

 

I am working on a VI that reads bunch of csv files (created by an application) using the built-in "Read from Spreadsheet File.vi" before combining it in a report using the excel report generation toolkit. "All rows" are being read from the csv file using the Read from Spreadsheet File.vi.

 

There are instances of csv files where it has an unwanted comma towards the end of the row causing an extra cell (with no data) to show up in the final report. I was wondering if there an easy way to remove it (rather than going through each and every row and getting rid of it).

 

Thanks!

0 Kudos
Message 1 of 6
(5,692 Views)
Solution
Accepted by topic author Troy12

You would have to go through each and every row, look at the last element, and delete it if it is an empty string.  But a For Loop makes this easy:

 

19323iAFA7BDFC805978EE  

 

Read spreadsheet, get 2D array of strings.  For each row, get last element.  Test if it is a blank.  If so, delete it from the array.  If not, pass array untouched.

- tbob

Inventor of the WORM Global
Message 2 of 6
(5,682 Views)

Thank you, tbob.

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

This looks like a job for a regex and Search and Replace or what I call Seek and Destroy.

 

19325i0CF8C7809F2A9317

 

I look for a comma followed by some non-digits and one or more newlines and replace with a simple newline.  If you don't like your CSV files to end with a newline, just use Trim Whitespace.vi

Message 4 of 6
(5,670 Views)

@Darin.K wrote:

This looks like a job for a regex and Search and Replace or what I call Seek and Destroy.

 

 


AAAAIIIIEEEEEE!!!!!  This forum is going regex crazy!Smiley Surprised  While I have nothing against regex, and I think it is a wonderful shortcut to many things, imagine what would happen if you inherited code with regex and you were not a regex expert (like 99% of the people here).  It would be a nightmare to modify the code.  What I would like to propose is that all regex users put a very good comment as to what the expression is doing.  Like Darrin K did:

 


 

I look for a comma followed by some non-digits and one or more newlines and replace with a simple newline. 


 

With a comment like this, I know exactly what is happening, and modifying the code is a lot easier.

 

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 6
(5,615 Views)

Got a problem with a string?

There's a regex for that....

0 Kudos
Message 6 of 6
(5,607 Views)