-
Couldn't load subscription status.
- Fork 0
ProtoString pad() Method
Seth Clydesdale edited this page Jun 12, 2015
·
1 revision
<< Back to Miscellaneous Methods
Padding the right side of a string once by passing no argument. Passing a number will apply the space n times.
'Coffee'.pad(); // returns 'Coffee '
'Coffee'.pad(6); // returns 'Coffee 'Passing a string as the second parameter will change the padding character.
'Coffee'.pad(6, '!'); // returns 'Coffee!!!!!!'
'Coffee'.pad(1, ' is good. :)'); // returns 'Coffee is good. :)'Passing left, right, or both as the third parameter changes the side where the padding is applied.
'Coffee'.pad(3, '♥', 'right'); // returns 'Coffee♥♥♥'
'Coffee'.pad(3, '♥', 'left'); // returns '♥♥♥Coffee'
'Coffee'.pad(3, '♥', 'both'); // returns '♥♥♥Coffee♥♥♥'The pad method is used to pad the side(s) of a string with whitespace or a specified character. It applies the padding character to the specified side(s) the specified number of times.
String.pad(n, str, type);| Parameter | Description |
|---|---|
| n | A number that defines the amount of characters to be padded onto the string's side(s). Defaults to 1 if left undefined. |
| str | A string that defines the character used for padding. Defaults to whitespace if left undefined. |
| type | A string that defines the padding method to be used. Possible values are left, right, and both. Defaults to right if left undefined. |
Home • History • ProtoString • Created by Seth Clydesdale