CSV(comma separated values) files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Johansson

    CSV(comma separated values) files

    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


  • rossum

    #2
    Re: CSV(comma separated values) files

    On Mon, 11 Aug 2008 13:49:19 +0200, "Tony Johansson"
    <johansson.ande rsson@telia.com wrote:
    >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
    >
    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'}.

    When you convert some data into a string for a CSV file much of the
    type information is lost.

    HTH

    rossum

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: CSV(comma separated values) files

      On Aug 11, 12:49 pm, "Tony Johansson" <johansson.ande rs...@telia.com >
      wrote:
      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

      Comment

      • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

        #4
        Re: CSV(comma separated values) files

        Tony Johansson wrote:
        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

        Comment

        • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

          #5
          Re: CSV(comma separated values) files

          rossum wrote:
          On Mon, 11 Aug 2008 13:49:19 +0200, "Tony Johansson"
          <johansson.ande rsson@telia.com wrote:
          >What does it mean when it says that there is no information about the data
          >types of the data extracted from a CSV file.
          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

          Comment

          • MC

            #6
            Re: CSV(comma separated values) files

            Strings are usually quoted and arrays not used in CSV, so some
            types can be ruled out.
            Speaking of which, is there an "official syntax" for CSV files somewhere,
            and/or a C# tool to parse them?


            Comment

            • John Baird

              #7
              Re: CSV(comma separated values) files

              http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm shows the rules for
              csv file creation. There are no standard c# tools that I know of to
              parse them, but the Code Project has a few public projects which will do
              this for you or point you in the right direction to roll your own.

              It's fairly easy to parse them by using the string.split functionality
              of c#. I have a number of samples if you need some help.




              "MC" <for.address.lo ok@www.ai.uga.e du.slash.mcwrot e in message
              news:#MZmJ4B$IH A.1224@TK2MSFTN GP02.phx.gbl:
              Strings are usually quoted and arrays not used in CSV, so some
              types can be ruled out.
              >
              Speaking of which, is there an "official syntax" for CSV files somewhere,
              and/or a C# tool to parse them?

              Comment

              • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

                #8
                Re: CSV(comma separated values) files

                MC wrote:
                >Strings are usually quoted and arrays not used in CSV, so some
                >types can be ruled out.
                >
                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:

                This RFC documents the format used for Comma-Separated Values (CSV) files and registers the associated MIME type "text/csv". This memo provides information for the Internet community.


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

                Arne

                Comment

                • Ken Foskey

                  #9
                  Re: CSV(comma separated values) files

                  On Mon, 11 Aug 2008 21:52:20 -0400, MC wrote:
                  >Strings are usually quoted and arrays not used in CSV, so some types
                  >can be ruled out.
                  >
                  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

                  Comment

                  • =?UTF-8?B?QXJuZSBWYWpow7hq?=

                    #10
                    Re: CSV(comma separated values) files

                    Ken Foskey wrote:
                    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

                    Comment

                    • uma devi

                      #11
                      Re: CSV(comma separated values) files


                      eg:
                      "uma","devi "
                      how can i get only strings without quotes and comma using c#

                      *** Sent via Developersdex http://www.developersdex.com ***

                      Comment

                      Working...