kotlin.text.trimMargin

trimMargin

fun String.trimMargin(marginPrefix: String = "|"): String

Trims leading whitespace characters followed by marginPrefix from every line of a source string and removes first and last lines if they are blank (notice difference blank vs empty).

Doesn't affect line if it doesn't contain marginPrefix except first and last blank lines.

Doesn't preserve original line endings.

Example

assertEquals("ABC\n123\n456", """