LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

How to idenify comma as data in CSV file

Highlighted

Hi,

 

I have a CSV file having data containing comma (,) in it.

 

So whe i read the file as the data contain(,) the data is read as two different value.

 

Can anyone suggest any idea or is there ay VI available to overcome this problem of having (,) as data for CSV file.

 

Anticipating response.

 

 

0 Kudos
Message 1 of 14
(678 Views)

Hi Alex,

 

Give a try using spread sheet string to array function and making delimeter as ,(comma). I think it will work out.. 

LV 8.0, 8.6, 2011,2012,2013 WinXP
0 Kudos
Message 2 of 14
(675 Views)

By definition, a CSV file has data separated by commas. That means you can't have commas in your data. Some implementations (Excel, for instance) allow you to have commas in your data if you wrap the data in double quotes (so 1,2,"3,4",5 will result in 4 columns) or escape it, but LV doesn't recognize that. You can see some more here - http://en.wikipedia.org/wiki/Comma-separated_values

 

The easiest thing to do is to use another delimiter and not call the file CSV. If you want to fix the existing file, you can probably open it in Notepad, put quotes around the relevant data, then open it in Excel and replace the commas with another character.


___________________
Try to take over the world!
0 Kudos
Message 3 of 14
(660 Views)

Are your "CSV" file data stored with a fixed number of bytes per field?  Can you look at the file and *know* that the comma is data and not a delimiter?  If you can know it, you can write a program to figure it out.  Perhaps you can show us some sample data and explain why a particular comma isn't a delimiter and we can help.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 4 of 14
(648 Views)

I am having the same issue. I have a CSV file that is comma delimited. One of data columns has value which contains a comma, but this data is wrapped in double quotes. I am using the Read Delimited Spreadsheet VI to parse the CSV data. However LabVIEW 2017 doesn't properly read the data because the value contains a comma, but this value is wrapped in double quotes.

 

Is there a solution to this issue without having having to the change the delimiter of the CSV file?

0 Kudos
Message 5 of 14
(318 Views)

The only thing I can think of is to "pre-process" your data by reading the text and using "search and replace" in a judicious manner.  Then use the "Spreadsheet String to Array" function to parse it all out.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 14
(309 Views)

Depending on how well formatted the file is, it can work with ", " (comma, space) as delimiter.

/Y

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
Message 7 of 14
(302 Views)

Great Zombie Discussion, i.e. broughT back from the DEAD.  lol.

 

It's a crying shame there isn't an input on the read delimited spreadsheet string VI that accounts for numbers with commas that are surrounded by double quotes.

 

Saving XLS files to .txt, or tab delimited, is truly the way to go.

 

I do like the idea of using  [   ","    ] as the separator, or even [   ,"   ] followed by a replace double quotes with nothing approach.  But, as said ...  the data has to be well behaved.

 

I guess it only comes as a problem when the data file is not 're-savable' from csv format to tab delimited format.  

 

Would love to chase this down but have bigger fish to fry, so to speak, at the moment.

-------
Mark Ramsdale
-------
0 Kudos
Message 8 of 14
(258 Views)

As long as it's well behaved there's really no problem, but if it's less so, e.g. a different amount of spaces, you'll have to use some cleaning. E.g. a regular expression search of \"(^\")+\" (if I managed to format that correctly, regular expressions is the closest thing to magic I know. ^^

/Y

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 14
(244 Views)

So I try to fry this little fish...

 

replace commas in quoted data.png

Greets, Dave
0 Kudos
Message 10 of 14
(234 Views)