Created
June 4, 2014 08:43
-
-
Save Wind4/7df2c4fd8bf1e4be677e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//pads left | |
String.prototype.lpad = function(padString, length) { | |
var str = this; | |
while (str.length < length) | |
str = padString + str; | |
return str; | |
} | |
//pads right | |
String.prototype.rpad = function(padString, length) { | |
var str = this; | |
while (str.length < length) | |
str = str + padString; | |
return str; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//trimming space from both side of the string | |
String.prototype.trim = function() { | |
return this.replace(/^\s+|\s+$/g,""); | |
} | |
//trimming space from left side of the string | |
String.prototype.ltrim = function() { | |
return this.replace(/^\s+/,""); | |
} | |
//trimming space from right side of the string | |
String.prototype.rtrim = function() { | |
return this.replace(/\s+$/,""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment