KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am passing some JSON to a server via a script (not mine) that accepts the JSON as a string. Some of the content of the JSON contains single quotes so I want to ensure that any single quotes are escaped before being passed to the script. I have tried the following: > irb > 1.9.3p194 :001 > x = "that's an awesome string" > => "that's an awesome string" > 1.9.3p194 :002 > x.sub("'", "\'") > => "that's an awesome string" > 1.9.3p194 :003 > x.sub("'", "\\'") > => "thats an awesome strings an awesome string" but can't seem to get the syntax right.
Tags (comma-separated)
Save Edits
Cancel