[squeak-dev] Re: The Inbox: Collections-topa.366.mcz
glenpaling
glenpaling at rogers.com
Fri Apr 15 20:38:18 UTC 2011
I say include it. I use it to create dictionary keys from a head while
importing delimited text files.
populateFrom: aReadStream delimitWith: delimiters labels: labelCollection
| numberOfFields newEntry item |
data := OrderedCollection new.
labels := labelCollection collect: [ :each | each withBlanksTrimmed
asCamelCase asSymbol ].
numberOfFields := labels size.
[aReadStream atEnd] whileFalse: [
item := (aReadStream nextLine) subStrings: delimiters.
newEntry := Dictionary new: numberOfFields.
item size > numberOfFields
ifTrue: [ self error: ['Number of data elements exeeds expected from
labels']].
labels withIndexDo: [:label :index |
newEntry at: label put: (item at: index ifAbsent: [nil]). ].
data add: newEntry.
].
--
View this message in context: http://forum.world.st/The-Inbox-Collections-topa-366-mcz-tp2257350p3452941.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.
More information about the Squeak-dev
mailing list
|