07-19-2010 03:59 PM
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!
Solved! Go to Solution.
07-19-2010 04:30 PM
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:
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.
07-19-2010 04:47 PM
Thank you, tbob.
07-19-2010 04:47 PM
This looks like a job for a regex and Search and Replace or what I call Seek and Destroy.
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
07-20-2010 09:49 AM
@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! 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.
07-20-2010 10:07 AM
Got a problem with a string?
There's a regex for that....