Uday kumar das Uday kumar das - 6 months ago 37
Ruby Question

remove `\"` from string rails 4

I have params like:

params[:id]= "\"ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6\""


And i want to get expected result as below:

"ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6"


How can I do this?

Answer

You can use gsub:

"\"ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6\"".gsub("\"", "")
=> "ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6"

Or, as @Stefan mentioned, delete:

"\"ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6\"".delete("\"")
=> "ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6"
Comments