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.
Fresh M. (Guest)
on 2009-03-04 21:57
If I have a array: a = [ "a", "a", "b", "b", "c" ]

How can I get a string: "a, a, b, b, c"
badboy (Guest)
on 2009-03-04 22:03
(Received via mailing list)
Fresh M. 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(', ')
Dominik H. (Guest)
on 2009-03-04 22:05
(Received via mailing list)
On [Thu, 05.03.2009 04:56], Fresh M. 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.