CSV parsing
Last updated at 7:06 am UTC on 28 June 2016
2016
As of 2016 use the following package
http://www.squeaksource.com/CSV/
by Arvi Bryant
MCHttpRepository
location: 'http://www.squeaksource.com/CSV'
user: ''
password: ‘'
or directly work with findTokens:escapedBy: (CSV parsing).
2006
Can anyone point to an up-to-date source for these methods?
Try: http://web.archive.org/web/*/http://nest.swiki.net/.uploads/String-csvSubstrings.st
Here are a couple of small methods to assist in working with CSV (Comma-Separated Values) files.
String-csvSubstrings.st
The first method is on String, and will take a CSV line and transform it into an ordered collection of substrings.
SequenceableCollection-asCSVLine.st
The second method is on SequenceableCollection (i.e., will work with OrderedCollection and Array) and will convert the objects in that collection into a CSV line.
Some code to read a CSV file:
|file rows|
rows _ OrderedCollection new.
file _ StandardFileStream fileNamed: 'someFileName.csv'.
file linesDo: [:line| rows addLast: line csvSubstrings].
rows inspect.
Chris Cunningham