padLeft
Adding char left of string.
Source
String.prototype.padLeft = function(len, c) {
var s = this, c = c || '0';
while (s.length < len) s = c + s;
return s;
};
Example
"123".padLeft(6, '0');
Result: 000123
ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods
Adding char left of string.
String.prototype.padLeft = function(len, c) {
var s = this, c = c || '0';
while (s.length < len) s = c + s;
return s;
};
"123".padLeft(6, '0');
Result: 000123