W3cubDocs

/Kotlin

trimIndent

fun String.trimIndent(): String

Detects a common minimal indent of all the input lines, removes it from every line and also removes first and last lines if they are blank (notice difference blank vs empty).

Note that blank lines do not affect detected indent level.

Please keep in mind that if there are non-blank lines with no leading whitespace characters (no indent at all) then the common indent is 0 so this function may do nothing so it is recommended to keep first line empty (will be dropped).

Doesn't preserve original line endings.

Example

assertEquals("ABC\n123\n456", """
                            ABC
                            123
                            456""".trimIndent())

Return deindented String

See Also

kotlin.text.isBlank

© 2010–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-indent.html