/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g, ""); }; String.prototype.ltrim = function(){ return this.replace(/^\s+/, ""); }; String.prototype.rtrim = function(){ return this.replace(/\s+$/, ""); }; String.prototype.padLeft = function(str, len, padChar) { if(!padChar) padChar = " "; while(str.length < len){ str = padChar+str; } return str; } String.prototype.padRight = function(str, len, padChar) { if(!padChar) padChar = " "; while(str.length < len){ str = str+padChar; } return str; } //opposite of String.slice; removes a section of a string and returns what's left String.prototype.prune = function(start, end) { var result = this.slice(0, start); if(!isNaN(end)) result += this.slice(end); return result; } String.prototype.rot13 = function() { var a=97, m=109, n=110, z=122, A=65, M=77, N=78, Z=90; var len = this.length, c, str = ""; for(var i=0; i<len; i++) { c = this.charCodeAt(i); if((a <= c && c <= m) || (A <= c && c <= M)) str += String.fromCharCode(c+13); else if((n <= c && c <= z) || (N <= c && c <= Z)) str += String.fromCharCode(c-13); else str += this[i]; } return str; }
Comments
