Skip to content

Instantly share code, notes, and snippets.

@Wind4
Created June 4, 2014 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wind4/7df2c4fd8bf1e4be677e to your computer and use it in GitHub Desktop.
Save Wind4/7df2c4fd8bf1e4be677e to your computer and use it in GitHub Desktop.
//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;
}
//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