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!
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!
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
http://www.cfcl.com/rdm Rich M.
http://www.cfcl.com/rdm/resume [email protected]
http://www.cfcl.com/rdm/weblog +1 650-873-7841
Technical editing and writing, programming, and web development
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
Jason
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs