
VW code to read comma-delimited text files??
Quote:
> Hello gang,
> Does anyone out there have any Smalltalk code to read in a
> comma-delimited text file? What we're specifically doing is read in
> such a file that was created by Excel.
> Thanks,
> Gary
Ive found the following method usefull:
!CharacterArray methodsFor: 'converting'!
unquotedCommaSeparatedValues
"Answer an Array of tokens from comma separated values, some of which
may be enclosed within double-quotes (and hence, contain commas)."
| tokens input nextToken |
input := self readStream.
tokens := Array new writeStream.
[input atEnd] whileFalse: [
(input peekFor: $") ifTrue: [
nextToken := input upTo: $" .
(input peekFor: $, ).
] ifFalse: [
nextToken := input upTo: $, .
].
tokens nextPut: nextToken.
].
^tokens contents
! !
-- Mike Klein
To programatically despam my email address, see:
http://www.*-*-*.com/ ~mklein/rot13ed.st
GO SMALLTALK -- GO VW2.5.2c