1

I have this string :

temp = "["minutes", "hours"]"

If I do this:

temp[1..-2].split(", ")

I get an array of 2 elements like this:

[0] = ""minutes""
[1] = ""hours""

How can I avoid to have double quotes?

code-gijoe
  • 6,949
  • 14
  • 67
  • 103

3 Answers3

4

Use the JSON parser :

JSON.parse(your_array)
Intrepidd
  • 19,772
  • 6
  • 55
  • 63
2

One more:

the_string.scan(/\"(\w+)\"/).flatten
 => ["minutes", "hours"]
forker
  • 2,609
  • 4
  • 23
  • 24
1

Just do:

temp.gsub("\"", "")[1..-2].split(", ")

Or, once you have the array with double quotes on each element:

temp.map{|e| e.squeeze("̣\"")}
Alfonso
  • 758
  • 5
  • 8