Forum: Ruby Putting string values into array

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jackster T. (Guest)
on 2008-11-21 20:35
I have a string that contians about 20 names that are all seperated by a
single white space. What is the easiest way to get those 20 names into
an array of 20 elements?

a = "first_name second_name third_name etc"

thanks

jack
Stefano C. (Guest)
on 2008-11-21 20:37
(Received via mailing list)
Alle Friday 21 November 2008, jackster the jackle ha scritto:
> I have a string that contians about 20 names that are all seperated by a
> single white space. What is the easiest way to get those 20 names into
> an array of 20 elements?
>
> a = "first_name second_name third_name etc"
>
> thanks
>
> jack

a.split ' '

Stefano
Mark T. (Guest)
on 2008-11-21 21:20
(Received via mailing list)
On Nov 21, 1:32 pm, Stefano C. <removed_email_address@domain.invalid> wrote:
> > jack
>
> a.split ' '

actually just

  a.split

is all you need.

-- Mark.
This topic is locked and can not be replied to.