Forum: Ruby Array to string

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.
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-03-04 20:57
If I have a array: a = [ "a", "a", "b", "b", "c" ]

How can I get a string: "a, a, b, b, c"
245a6d22816ecaeac1c9080ad183b859?d=identicon&s=25 badboy (Guest)
on 2009-03-04 21:03
(Received via mailing list)
Fresh Mix schrieb:
> If I have a array: a = [ "a", "a", "b", "b", "c" ]
>
> How can I get a string: "a, a, b, b, c"

[ "a", "a", "b", "b", "c" ].join(', ')
47aff267a58c012d222fd4d74f6beb54?d=identicon&s=25 Dominik Honnef (Guest)
on 2009-03-04 21:05
(Received via mailing list)
On [Thu, 05.03.2009 04:56], Fresh Mix wrote:
> If I have a array: a = [ "a", "a", "b", "b", "c" ]
>
> How can I get a string: "a, a, b, b, c"

By using Array#join
  >>> irb
  >> a = [ "a", "a", "b", "b", "c" ]
  => ["a", "a", "b", "b", "c"]
  >> a.join(", ")
  => "a, a, b, b, c"
This topic is locked and can not be replied to.