.padStart()
Anonymous contributor
Anonymous contributor5 total contributions
Anonymous contributor
Published Oct 27, 2023
Contribute to Docs
The .padStart()
method pads the beginning of a string with the specified fill character. The character will be used to meet the overall length specified by the first argument given. If no character is provided the padding will be whitespace by default.
Syntax
String.padStart(length, padChar)
String
: The string to be modified.length
: An integer that represents the total length of the string returned (with padding).padChar
: The character to be used (enclosed by''
) as padding, defaults to whitespace.
Example
The example below demonstrates the use of .padStart()
to pad a string.
fun main() {val str = "codecademydocs"val str2 = str.padStart(14)println(str2)val str3 = str.padStart(18, '-')println(str3)}
The output of this code will be:
'codecademydocs''----codecademydocs'
All contributors
- Anonymous contributorAnonymous contributor5 total contributions
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.