I''m fairly new to Ruby and I''ve got a question concerning string parsing. If I want to take a comma-delimited string of words and put each word into an array, how would I do it? Example: string = "one, two, three, four" Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
At 5:55 PM +0200 4/2/07, Nick wrote:> I''m fairly new to Ruby and I''ve got a question concerning string > parsing. If I want to take a comma-delimited string of words and > put each word into an array, how would I do it? > > Example: > string = "one, two, three, four">> string.split(/,\s*/)=> ["one", "two", "three", "four"] -r Note - Generic Ruby questions should probably be addressed to ruby-talk-X+L+6nJQZ58h9ZMKESR00Q@public.gmane.org -- http://www.cfcl.com/rdm Rich Morin http://www.cfcl.com/rdm/resume rdm-go8te9J4rpw@public.gmane.org http://www.cfcl.com/rdm/weblog +1 650-873-7841 Technical editing and writing, programming, and web development --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
array = string.split('','')
or to make sure there''s no extra white space (I think)
array = string.split('',\s*'')
Please go read:
http://www.rubycentral.com/book/
and check out
http://ruby-doc.org/core
Jason
On 4/2/07, Nick
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> I''m fairly new to Ruby and I''ve got a question concerning
string
> parsing. If I want to take a comma-delimited string of words and put
> each word into an array, how would I do it?
>
> Example:
> string = "one, two, three, four"
>
> Thanks!
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---