prettify

baseline

String.prototype javascript

String.prototype.PadLeft = function (nLen, sPad) {
   
if (typeof sPad !== "string") sPad = " ";
   
if (typeof nLen !== "number") nLen = 2;
   
var sResult = this;
   
while (sResult.length < nLen) sResult = sPad + sResult;
   
return sResult;
};
String.prototype.PadRight = function(sPad, nLen) {
   
if (typeof sPad !== "string") sPad = " ";
   
if (typeof nLen !== "number") nLen = 2;
   
var sResult = this;
   
while (sResult.length < nLen) sResult += sPad;
   
return sResult;
};
String.prototype.Trim = function () {
   
return this.replace(/^\s+|\s+$/g, "");
};
String.prototype.TrimLeft = function () {
   
return this.replace(/^\s+/, "");
};
String.prototype.TrimRight = function () {
   
return this.replace(/\s+$/, "");
};

No comments:

Post a Comment