What is the simplest way to create a collection from a text file in CSV format?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

What is the simplest way to create a collection from a text file in CSV format?

Andy Burnett
I have a small database containing questionnaire responses. The DB can output the responses (mainly descriptive paragraphs) in CSV format.  Ideally, I would like to read each of the records into a collection of some kind.  I was hoping that there might be a 'fromCSV:' method, but I haven't found one.  One approach I had thought about was to edit the text so in order to create a series of array definitions, and then paste that into a workspace. However, that does lack a bit of elegance! So, is there a neat way of doing this?

Cheers
AB

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: What is the simplest way to create a collection from a text file in CSV format?

Zulq Alam-2
I ususally do something like this:

(((FileStream readOnlyFileNamed: 'file.csv')
   contentsOfEntireFile                   " read and close "
     findTokens: String crlf)             " split into lines "
       reject: [:e | e isEmpty])          " lose empty lines "
         collect: [:e | e findTokens: $,] " split into fields "

Regards,
Zulq.

Andy Burnett wrote:

> I have a small database containing questionnaire responses. The DB can
> output the responses (mainly descriptive paragraphs) in CSV format.  
> Ideally, I would like to read each of the records into a collection of
> some kind.  I was hoping that there might be a 'fromCSV:' method, but I
> haven't found one.  One approach I had thought about was to edit the
> text so in order to create a series of array definitions, and then paste
> that into a workspace. However, that does lack a bit of elegance! So, is
> there a neat way of doing this?
>
> Cheers
> AB
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: What is the simplest way to create a collection from a text file in CSV format?

Andy Burnett
In reply to this post by Andy Burnett

<<I ususally do something like this:

(((FileStream readOnlyFileNamed: 'file.csv')
  contentsOfEntireFile                   " read and close "
    findTokens: String crlf)             " split into lines "
      reject: [:e | e isEmpty])          " lose empty lines "
        collect: [:e | e findTokens: $,] " split into fields "

Regards,
Zulq.>>

Andy Burnett wrote:
> I have a small database containing questionnaire responses. The DB can
> output the responses (mainly descriptive paragraphs) in CSV format.
> Ideally, I would like to read each of the records into a collection of
> some kind.  I was hoping that there might be a 'fromCSV:' method, but I
> haven't found one.  One approach I had thought about was to edit the
> text so in order to create a series of array definitions, and then paste
> that into a workspace. However, that does lack a bit of elegance! So, is
> there a neat way of doing this?
>
> Cheers
> AB

That's great Zulq, much better than my rather procedural attempts.

thanks
AB

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners