Arvind
Arvind

Reputation: 2781

String array to sentence ruby 1.9.3

I have tried to convert it to the array and then try to use join(',') but this is not converting in a sentence can any buddy help on it. convert this string

"[\"one\", \"two\", \"three\"]"

to sentence one, two, three

Updated:

**Solved this by gsub

.gsub(/(\[\"|\"\])/, '').split('", "')

I have used this and got [" one", "two", "three"], is there any other way to convert it like this

Upvotes: 0

Views: 145

Answers (1)

Bryan Oemar
Bryan Oemar

Reputation: 926

Definitely not the prettiest of solutions, but you could have done something like:

eval("[\"one\", \"two\", \"three\"]")

Upvotes: 1

Related Questions