Skip to content

Instantly share code, notes, and snippets.

@dineshsprabu
Created August 17, 2016 11:13
Show Gist options
  • Save dineshsprabu/75d0ed84d295ca28040b3502806e5377 to your computer and use it in GitHub Desktop.
Save dineshsprabu/75d0ed84d295ca28040b3502806e5377 to your computer and use it in GitHub Desktop.
[RUBY] Escaping single quote, double quotes and comma properly
def escape_string str
str.gsub!(/\"/,'\\u0022') if str.include? '"'
str.gsub!(/\'/,'\\u0027') if str.include? "'"
str.gsub!(/\,/,'\\u002C') if str.include? ","
str
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment