How to split csv line?

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

How to split csv line?

Sergei Gnezdov
What is an easy way to split text line with comma separated values?

For example, if line is
    first, second value, third
I'd like to be able to have an ordered collection with three elements in it:
    first
    second value
    third


Thank you


Reply | Threaded
Open this post in threaded view
|

Re: How to split csv line?

Andy Bower
Sergei,

> What is an easy way to split text line with comma separated values?
>
> For example, if line is
>     first, second value, third
> I'd like to be able to have an ordered collection with three elements in
it:
>     first
>     second value
>     third

Try:

'first,second,third' subStrings: $,

Or, if your string contains whitespace which you want to get rid of:

('first, second, third' subStrings: $,) collect: [:each | each trimBlanks]

Best Regards,

Andy Bower
Dolphin Support
http://www.object-arts.com
---
Are you trying too hard?
http://www.object-arts.com/Relax.htm
---