LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the fastest way to programmatically Parse a .csv file?

Hi,

 

I have a csv file of size more than 200KB. The source code should have the capability to read, compare and write to the same .csv file. This .csv file is obtained from a .xls file. The data in the file is delimited by comma and also it has strings within double quotes. writing to the .csv file should be in the specified location exactly matching the number of columns or rows in .xls file. I mean to say the file should be in the same manner as it was in .xls.

 

Can anyone please suggest me on how to achieve this?

 

Thanks

0 Kudos
Message 1 of 2
(3,249 Views)

You can always use regular expressions, there's a CVI library or function panel that supports the use of RE's.  There are a couple of quirks to NI's implementation but they do work.  With RE's you're essentially guaranteed you can find anything anywhere in a text file, but it may be a bit painful to nail down the exact expressions you'll need.

 

Another approach might be to use Excel under control of CVI.  Excel will import/export CSV's.  You could fire up Excel, import the CSV, run a macro, and export the results as another CSV, all under the control of CVI.

 

Yet another approach would be to use the parsing functions in the standard C library.  CVI has some additional parsing functions available in one of their libraries as I recall.

 

I would tend to use RE's to do the job since you can always create an RE that will do exactly what you want, but there is a learning curve if you aren't familiar with them.

0 Kudos
Message 2 of 2
(3,237 Views)