LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parse Date with "," correctly from CSV file

Solved!
Go to solution

In the attached VI, I have a CSV file that contains a Time Stamp with "," in the first column.  When I try to generate the array from the original file, I get two extra columns with part of the date occupying the following columns because of the ","s in the Time Stamp column.  Is there a simple solution to parse the date correctly to be limited to the first column and not be split up into 3 columns as in the attached VI?  

 

Note that this is a snippet of the full data file.  There are thousands of rows.

 

Thanks for your help and time.

0 Kudos
Message 1 of 7
(3,245 Views)

The "short" answer....use a "short" date when writing the datestamp to the CSV file.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 7
(3,238 Views)

Read the first row separately and parse.

 

Read the remainder and parse.  Work with the first 3 columns to merge them into one deleting the other 2.

Put row 1 with that array.

Message 3 of 7
(3,231 Views)

I came up with this as per your suggestion:

 

 

Capture.PNG

Is this what you meant?  If so, can this be simplified?

 

Thanks!

 

 

0 Kudos
Message 4 of 7
(3,216 Views)

After you get passed the first line (headers), you can use Scan From String to get the values into usable numbers (if that is desirable for you). 

 

formatString.png

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 5 of 7
(3,203 Views)
Solution
Accepted by topic author hiNI

You can try this, do not know if it is more efficient, but it is a bit more compact.

 

mcduff

Other case wire straight throughOther case wire straight through

 

Message 6 of 7
(3,197 Views)

As you undoubtedly know, a CSV (Comma-Separated Values) file uses commas to separate fields.  If your data consists of a TimeStamp that has exactly two embedded commas and N other numeric fields (all comma-separated), then (as you note) you'll get the Time information returned as three fields followed by the N Data Fields.

 

Rather than trying to re-invent the Parse, what I would recommend is to take your (3+N)-column 2D array and pass it through a For loop (which treats the rows one at a time).  Split out the first three (Time-stamp) entries, recombine them by adding the commas back in (giving you back your TimeStamp), then "do something intelligent" with the TimeStamp to create a (1+N)-column row consisting of TimeStamp value + N data values.  I'm being a bit vague here as I don't know if you are trying to read the CSV file as text or numerics, so don't know how you want to express the TimeStamp data (if everything is text, then the fix is almost trivial -- you can combine the three sub-strings with a single Format into String function with three string inputs and a Format String of $s,$s,$s (three strings, separated by the "missing" commas).

 

Bob Schor

Message 7 of 7
(3,165 Views)