Click to See Complete Forum and Search --> : JS RPAD & LPAD functions


Caliban
07-09-2003, 03:42 PM
Hi y'all, JS gurus out there! :)

Are there an equivalent functions for RPAD (right justification) and LPAD (left justification)

I need something like this:

myVarLEFT = LPAD(myValue, 6, '*')
That is, fill with '*' to the left

myVarLEFT = RPAD(myValue, 6, '*')
That is, fill with '*' to the right

(LPAD and RPAD are Oracle formatting functions, but I know you catch the idea, don't you?)


Any ideas? They'll be gratefully received.

Thanx In Advance

Charles
07-09-2003, 04:24 PM
No, but they're easily made but JavaScript being an OOP language they'll look a wee bit different:

<script type="text/javascript">
<!--
String.prototype.lPad = function (n,c) {var i; var a = this.split(''); for (i = 0; i < n - this.length; i++) {a.unshift (c)}; return a.join('')}

String.prototype.rPad = function (n,c) {var i; var a = this.split(''); for (i = 0; i < n - this.length; i++) {a.push (c)}; return a.join('')}

alert ('foo'.lPad(6,'*'))
// -->
</script>

Caliban
07-09-2003, 08:37 PM
Hi Charles,
thanx 4 the info, it really worked!

... and now, a new question:

it's possible to set programatically the width of the browser window?


T.I.A.