/    Sign up×
Community /Pin to ProfileBookmark

JS RPAD & LPAD functions

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

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CharlesJul 09.2003 — [font=georgia]No, but they're easily made but JavaScript being an OOP language they'll look a wee bit different:[/font]

[font=monospace]<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>[/font]
Copy linkTweet thisAlerts:
@CalibanauthorJul 10.2003 — 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.
×

Success!

Help @Caliban spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...