function zeroPad(num, places){
var zero = places - num.toString().length + 1;
return Array(+(zero > 0 && zero)).join("0") + num;
}
Please tell me the means of code above, and how to use it on C#
function zeroPad(num, places){
var zero = places - num.toString().length + 1;
return Array(+(zero > 0 && zero)).join("0") + num;
}
Please tell me the means of code above, and how to use it on C#
The code is Javascript and pads the number num
with zeros to the length places
, for example zeroPad(12, 4)
gives you 0012
. In C# you can do this with the PadLeft()
method, for example 12.ToString().PadLeft(4, '0')
which gives you the same as above 0012
.