On 21 Sep 2014, at 21:57, Markus Fritsche <mfritsche@reauktion.de> wrote:
On 2014-09-21 20:52, Sven Van Caekenberghe wrote:
Hi Markus,
NeoCSVReader is not like most CSV readers
(NeoCSVReader on: '"COL1";"COL2";"COL3";"DESCRIPTION" 1;"A string";13;"This is a long description spanning multiple lines, which is a challenge for most csv readers!" 2;"Another string";42;""' readStream) separator: $; ; upToEnd.
Awesome. I must have been sleeping when I did my first test.
Next question - if I might: is there a quick way to read the header and get the records read into dictionaries?
| reader | reader := NeoCSVReader on: 'A,B,C\1,2,3\3,4,5\6,7,8' withCRs readStream. reader readHeader do: [ :each | reader addFieldAt: each ]. reader recordClass: Dictionary. reader upToEnd. => an Array( a Dictionary('A'->'1' 'B'->'2' 'C'->'3' ) a Dictionary('A'->'3' 'B'->'4' 'C'->'5' ) a Dictionary('A'->'6' 'B'->'7' 'C'->'8' )) Is that quick enough ? You could also say, each asSymbol or use #addFieldAt:converter: Even shorter is to replace the second line by reader addFieldsAt: reader readHeader. Sven
Regards, Markus