CSV(comma separated values) files

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

What does it mean when it says that there is no information about the data
types of the data extracted from a CSV file.

Can somebody this.

//Tony
 
What does it mean when it says that there is no information about the data
types of the data extracted from a CSV file.

It would help if you'd clarify what "it" is here.

Jon
 
Tony said:
What does it mean when it says that there is no information about the data
types of the data extracted from a CSV file.

The CSV does not contain information about the data type of each column.

It will be a guess based on the values.

Arne
 
Take a simple example, a CSV file containing "123". You cannot tell
from the CSV file alone whether this is the integer 123, the double
123.0, the string "123" or the character array {'1', '2', '3'}.

Strings are usually quoted and arrays not used in CSV, so some
types can be ruled out.

Arne
 
MC said:
Speaking of which, is there an "official syntax" for CSV files somewhere,
and/or a C# tool to parse them?

I don't think there is a general definition.

But most programmers have an idea about what it is.

Export/import from/to Access shows some of the options.

The most common format is:
- comma between fields
- double quotes around text
- double quotes within text doubled
- one record per line

There actually is a standard:

http://tools.ietf.org/html/rfc4180

but it i snot my impression that it is widely used
as a reference.

Arne
 
Speaking of which, is there an "official syntax" for CSV files
somewhere, and/or a C# tool to parse them?

I would strongly recommend that you don't use CSV at all. I believe that
CSV is the worst possible method of delivering data. I am aware of Excel
exporting data to CSV that imported differently.

Different programs do that handle Quotes properly for example 'O'Donnell'
should be 'O''Donnell'. If you have quote comma you are totally lost
'1 degree 0', something' A parser would take that as two fields, but is
it extracted as :1 degree 0:, :something': or as :something:. You can
never tell.

Ken

Ken
 
Ken said:
I would strongly recommend that you don't use CSV at all. I believe that
CSV is the worst possible method of delivering data.

The format has worked for a few decades. It can not be completely
hopeless. Usually the developers get it working.

I would also prefer XML as format, if starting white a blank
piece of paper. But that is often not the case. There are
lots of software out there that uses CSV.

Arne
 
Back
Top