Borrar filtros
Borrar filtros

reading quoted strings with comma in a csv file

10 visualizaciones (últimos 30 días)
Mahesh
Mahesh el 4 de Feb. de 2014
Comentada: Al in St. Louis el 20 de Mayo de 2022
Hi,
What is the best way to handle common in a CSV file .
For example I have a Comma separated value like the following .
123,'where are, you going',345,city
I was not able to read the above properly , because matlab was considering the comma after """where are, """ as a separator .But this comma is actually a part of value .
Could you please let me know how to handle this with regular expression ?
regards Mahesh

Respuestas (2)

Dahai Xue
Dahai Xue el 28 de En. de 2015
Editada: Dahai Xue el 28 de En. de 2015
On a PC with Excel installed, it is easy to use this statement
[~, ~, myTable] = xlsread('myFile.csv').
It handles quotes nicely. The 1st output is for numeric data only, and 2nd for strings only, while the 3rd for both in cells. The 3rd output must be used to keep the headers in the table.
  1 comentario
Al in St. Louis
Al in St. Louis el 20 de Mayo de 2022
Thank you. I can't believe that readtable still can't parse this correctly.

Iniciar sesión para comentar.


per isakson
per isakson el 4 de Feb. de 2014
Editada: per isakson el 4 de Feb. de 2014
Try textscan in combination with
'%q'
String, where double quotation marks indicate text to keep together
Single quotation mark might not be supported.
See the answer on comma and point decimal separator. You might be able to use that method to replace single quotes by double quotes.

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by