.prependIndent()
abereFejiro995340965013 total contributions
Published Nov 2, 2023
Contribute to Docs
The .prependIndent()
method in Kotlin is used to add indentation to a string
. It is useful for formatting text, especially when it’s needed to align or indent lines within a string
.
Syntax
fun String.prependIndent(indent: String = " "): String
String
: The string to add indentation to.indent: String
: The indentation to add to the string.
Example
This example shows how to use the .prependIndent()
method to add three spaces of indentation to the beginning of the string
:
fun main() {val originalText = "'This is an indented string.'"val indentedText = originalText.prependIndent(" ")println(indentedText)}
The above code will return the following output:
'This is an indented string.'
All contributors
- abereFejiro995340965013 total contributions
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.