Orsay Orsay - 1 year ago 80
Ruby Question

Delete elements from string + transform it into array

I have this string :

data = "[\"super\", \"cool!\", \"bien écrit\", \"first!\", \"why is everyone speaking French here?\"]"

I would like to transform it to be like :
data = ["super", "cool!", "bien écrit", "first!", "why is everyone speaking French here?"]

Answer Source

Parse it like a JSON. Try

require 'json'
data = JSON.parse data
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download