Right Pad

From SwiftAPI

Jump to: navigation, search

Right pad a string with a specified character. Also known as left justify.

Contents

C#

System.String : public string PadRight(int totalWidth)
System.String : public string PadRight(int totalWidth, char paddingChar)

JavaScript

var a = 'Text';
var b = 6;
var c = '-';
var d = a;
while(d.length < b) {
  d += c;
}
// d == '--Text'

PHP

php.net

string str_pad ( string $input , int $pad_length [, string $pad_string = " " [, int $pad_type = STR_PAD_RIGHT ]] )
$a = 'Text';
$b = 6;
$c = '-';
$d = str_pad($a, $b, $c, STR_PAD_RIGHT);
// $d == 'Text--'

Python

docs.python.org

a = 'Text'
b = 6
c = '-'
d = a.ljust(b, c)
# d == 'Text--'

Ruby

Ruby-Doc.org

a = 'Text'
b = 6
c = '-'
d = a.ljust(b, c)
# d == 'Text--'
Personal tools