Description
The padLeft function returns a new string of a specified length. The beginning of the original string is padded with the specified filler character until the desired length is reached.
Syntax
padLeft(string, length, filler)
Arguments
| Argument | Description |
|---|---|
string |
The original string that needs to be padded. |
length |
The desired total length of the returned string. |
filler |
The character used to pad the string. |
Return Types
The function returns a new string with the specified length, padded with the specified filler character.
Examples
| Description | Formula |
|---|---|
| Pad a string with zeros |
padLeft("123", 6, "0")
Result: |
| Pad a string with spaces |
padLeft("abc", 5, " ")
Result: |
| Pad a string with a special character |
padLeft("test", 8, "-")
Result: |
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 character should be a single character. If multiple characters are provided, only the first character is used.
Comments
0 comments
Please sign in to leave a comment.