Javascript String escape(str)

Description

Javascript String escape(str)


String.prototype.escape = function(str) {
    return str//w w  w.j  a v a2s .  c o  m
        .replace(/\\n/g, "\\n")
        .replace(/\\'/g, "\\'")
        .replace(/\\"/g, '\\"')
        .replace(/\\&/g, "\\&")
        .replace(/\\r/g, "\\r")
        .replace(/\\t/g, "\\t")
        .replace(/\\b/g, "\\b")
        .replace(/\\f/g, "\\f");
};



PreviousNext

Related