Description
The padRight
function returns a new string with a specified length, where the end of the current string is padded with the specified filler character.
Syntax
padRight(string, length, filler)
Arguments
Argument | Description |
---|---|
string |
The original string that needs to be padded. |
length |
The desired length of the output string. |
filler |
The character used to pad the string. |
Return Types
The function returns a string with the specified length, right-padded with the filler character.
Examples
Description | Example |
---|---|
Pad a string with spaces |
padRight("Test", 8, " ")Result: "Test " |
Pad a string with a character |
padRight("Test", 8, "-")Result: "Test----" |
String already has the desired length (no padding) |
padRight("Test", 4, "*")Result: "Test" |
Notes
- If the length of the original string is greater than or equal to the specified length, the original string is returned unchanged.
- The
filler
argument must be a single character.
Comments
0 comments
Please sign in to leave a comment.