• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: reading (parsing) CSV (or Excel) data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reading (parsing) CSV (or Excel) data


  • Subject: Re: reading (parsing) CSV (or Excel) data
  • From: BareFeet <email@hidden>
  • Date: Fri, 2 Oct 2009 10:55:51 +1000

On 02/10/2009, at 10:22 AM, Jens Alfke wrote:

If the data's not too huge, you can read the file into an NSString, break that into lines (there are some NSString methods for this, but I don't remember their names), and then on each line call [line componentsSeparatedByString: @","] to get the values in an NSArray.

That won't work. CSV can contain commas and newlines within items if encapsulated in quotes.


The values will be strings not numbers, but you can call -intValue or -doubleValue on each one to convert it.

Yes, CSV doesn't specify types, just strings, so any interpretation you make on types is after the actual CSV import.


I found this method (the one under the heading "General CSV"), which works fine, caters for delimiters within quotes, escaped quotes etc:

http://macresearch.org/cocoa-scientists-part-xxvi-parsing-csv-data

Tom
BareFeet

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >reading (parsing) CSV (or Excel) data (From: Colin Howarth <email@hidden>)
 >Re: reading (parsing) CSV (or Excel) data (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: reading (parsing) CSV (or Excel) data
  • Next by Date: Re: reading (parsing) CSV (or Excel) data
  • Previous by thread: Re: reading (parsing) CSV (or Excel) data
  • Next by thread: Re: reading (parsing) CSV (or Excel) data
  • Index(es):
    • Date
    • Thread