Skip to content

Instantly share code, notes, and snippets.

@Victa
Created June 14, 2011 13:28
Show Gist options
  • Save Victa/1024891 to your computer and use it in GitHub Desktop.
Save Victa/1024891 to your computer and use it in GitHub Desktop.
addSlashes / stripSlashes Javascript
String.prototype.addSlashes = function()
{return this.replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');};
String.prototype.stripSlashes = function()
{return this.replace(/\\(.?)/g, function (s, n1){switch (n1){case '\\':return '\\';case '0':return '\u0000';case '':return '';default:return n1;}});};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment