Reputation: 10885
Hi i want to remove quotes around this string
str = "[Date.UTC(2012,07,03,04,07,09),2.0]"
and want result like this
[Date.UTC(2012,07,03,04,07,09),2.0]
Any help will be apperciated...
Thanks
Upvotes: 1
Views: 2121
Reputation: 230346
I think you want eval
. It takes a string and evaluates it as ruby code.
str = "[Date.UTC(2012,07,03,04,07,09),2.0]"
a = eval str
By the way, this string isn't valid ruby code. Primarily because 09
is parsed as octal number, and 09
is not a valid octal number. Secondly, there's no UTC
method on Date
class (in the stdlib, anyway).
If you want to take this string and pass it to javascript, then just render it in the template.
# action.html.erb
<%= javascript_tag do %>
<%= str %>
<% end %>
Upvotes: 3
Reputation: 51156
If you're truly just asking about string manipulation... If the quotes are at the beginning and end of the string...
str = "abcdef"
trimmed = str[1..-2] #equals "bcde"
Upvotes: 2