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", """ABC
                            |123
                            |456""".trimMargin())

Parameters

marginPrefix - non-blank string, characters to be used as a margin delimiter. Default is | (pipe character).

Return deindented String

See Also

kotlin.text.isWhitespace

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

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部