rpad (JavaScript)

Fills a string on the right.

Defined in

String (Standard - JavaScript)

Syntax

rpad(ch:string, length:int) : string
Parameters Description
ch One or more characters. This pattern is repeated until the length parameter is satisfied.
length The "length" of the output string:
  • Subtract the length of the string from this parameter. The pattern is repeated the number of times indicated by the remainder.
  • If the specified length is less than or equal to the input string length, the output string is the same as the input string (no filling occurs).
Return value Description
string The output string.

Examples

(1) This example returns [#Paris Moscow Tokyo#].
function p(stuff) {
 	stuff = stuff.lpad("[#", stuff.length() + 1);
	stuff = stuff.rpad("#]", stuff.length() + 1);
	return stuff
}

var cities = new String("Paris   Moscow   Tokyo");
return p(cities)
(2) This example returns ###Paris Moscow Tokyo###.
function p(stuff) {
 	stuff = stuff.lpad("#", stuff.length() + 3);
	stuff = stuff.rpad("#", stuff.length() + 3);
	return stuff
}

var cities = new String("Paris   Moscow   Tokyo");
return p(cities)