Array to string

If I have a array: a = [ “a”, “a”, “b”, “b”, “c” ]

How can I get a string: “a, a, b, b, c”

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(’, ')

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs