The following functions allow you to Left or Right pad a string with a specified number of characters.
LPad(pStart,pTotalSize,pPad)
RPad(pStart,pTotalSize,pPad)
<script type="text/javascript">
<!--
// These functions return strings padded with
// the appropriate number of padding characters
// either on the left or right of the starting
// string.
//
// pStart - Starting string or number
// pTotalSize - Total length of completed string
// pPad - Character to use for padding
//
// http://www.mattbits.co.uk
function LPad(pStart,pTotalSize,pPad) {
var vPadding;
pStart = pStart.toString();
if (pTotalSize > pStart.length)
{
for (i=0; i < (pTotalSize-pStart.length); i++)
{
vPaddedString += pPad;
}
}
return vPadding + pStart.toString();
}
function RPad(pStart,pTotalSize,pPad) {
var vPadding;
pStart = pStart.toString();
if (pTotalSize > pStart.length)
{
for (i=0; i < (pTotalSize-pStart.length); i++)
{
vPaddedString += pPad;
}
}
return pStart.toString() + vPadding;
}
//-->
</script>