LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CSV string to spreadsheet-array

Hi Folks,
      Have you ever had a question that you felt certain had a simple answer - so hesitated to ask it?  Did you brute-force a solution to avoid admitting you were stuck?  I'm stuck!  What's worse, I know I've done this before, but don't remember how. Smiley Tongue
 
I'm looking for a clean way to convert a CSV file into a 2D array of strings, where some cell-values have embedded commas - and those values have been quoted.
 
A 3-column CSV file might like this:
Bible, "Eats, Shoots, and Leaves", Koran
God, Lynn Truss, Muhammed
 
I'll have a brute-force solution momentarily, but will gladly replace it with your simple solution.
 
Cheers!
 
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 1 of 8
(5,459 Views)

I would use a perl script because I could do it quickly and then I would feed the output to LabVIEW if I felt like LabVIEW was the best solution for the next step.

I'm starting to like LabVIEW because I can do some things quickly. I view software like a toolbox. Sometimes you pull out a screw driver

other times you need an expensive tool.

0 Kudos
Message 2 of 8
(5,446 Views)
Hey gchristi1,
      While it would be simple to shell-out to a [Active-] Perl-script - I'll probably stick with this LabVIEW work-around - until some kind soul shares a cleaner way (in LabVIEW, of course!)
 
 
Cheers.
 
P.S. To me, LabVIEW is a 4WD SUV. Smiley Wink 

Message Edited by tbd on 09-23-2007 01:00 AM

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Download All
0 Kudos
Message 3 of 8
(5,433 Views)

Could you save in 7.1 or post or explain what is in the other cases of the case structure?

I've been trying to replicate it but haven't figured it out yet.

Thanks.

LabVIEW user since 2.0
0 Kudos
Message 4 of 8
(4,778 Views)
Dont expect a reply as this post is 3 years old. I tried to downconvert the vi for you but the lowest i can convert to is version 8, so will be no good for you. I know for a fact though that this problem has come up again recently as i remember reading a recent thread about it. Perhaps keep searching on the forum for the solution. Rgs, Lucither
------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
Message 5 of 8
(4,757 Views)
If you don't get a response, post a request in the downconvert requests thread.
0 Kudos
Message 6 of 8
(4,743 Views)

Hi NimbleThink,

      Sorry for slow response (it's an employment thing...)

 

I can't down-convert for you, but I can explain the logic: 

The short answer is that it looks for delimiters one at a time.  If it finds a comma-quote, the beginning of a quoted-string, then the next delimiter must be a quote-comma - skipping single-commas between quotes.  If any other delimiter is matched then the next delimiter can be comma-quote OR quote-comma OR comma. 

 

Hidden code:

   If the outside case is True, empty-string is passed-out (loop quits anyway.)

   The one other [nested] case is "Default" and passes-out exactly the same regular-expression as initializes the shift-register.

 

By the way, in the "regular expression" the '|' means "OR".

 

Cheers!

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Message 7 of 8
(4,729 Views)

Thanks for the reply!

 

OK, the pipe character in Match Pattern is new in version 8, so I don't have access to it.

I'll re-write with several Match Patterns in parallel to achieve the same result.

LabVIEW user since 2.0
0 Kudos
Message 8 of 8
(4,667 Views)