trimIndent
所在位置是kotlin.text.trimIndent
,其相關用法介紹如下。
用法:
檢測所有輸入行的公共最小縮進,將其從每一行中刪除,如果第一行和最後一行為空白(注意空白與空的區別),則還刪除它們。
請注意,空行不會影響檢測到的縮進級別。
如果存在沒有前導空白字符的非空行(根本沒有縮進),則公共縮進為 0,因此此函數不會更改縮進。
不保留原始行尾。
例子:
import java.util.Locale
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val withoutIndent =
"""
ABC
123
456
""".trimIndent()
println(withoutIndent) // ABC\n123\n456
//sampleEnd
}
輸出:
ABC 123 456
也可以看看
相關用法
- Kotlin trimMargin用法及代碼示例
- Kotlin toTypedArray用法及代碼示例
- Kotlin then用法及代碼示例
- Kotlin toByteArray用法及代碼示例
- Kotlin take用法及代碼示例
- Kotlin toBooleanStrict用法及代碼示例
- Kotlin takeWhile用法及代碼示例
- Kotlin takeLastWhile用法及代碼示例
- Kotlin to用法及代碼示例
- Kotlin takeLast用法及代碼示例
- Kotlin toBooleanStrictOrNull用法及代碼示例
- Kotlin thenComparator用法及代碼示例
- Kotlin titlecase用法及代碼示例
- Kotlin toSortedMap用法及代碼示例
- Kotlin thenBy用法及代碼示例
- Kotlin toProperties用法及代碼示例
- Kotlin toList用法及代碼示例
- Kotlin thenByDescending用法及代碼示例
- Kotlin thenDescending用法及代碼示例
- Kotlin toString用法及代碼示例
- Kotlin associateBy用法及代碼示例
- Kotlin all用法及代碼示例
- Kotlin map用法及代碼示例
- Kotlin filterNot用法及代碼示例
- Kotlin reduceRight用法及代碼示例
注:本文由純淨天空篩選整理自kotlinlang.org大神的英文原創作品 kotlin.text.trimIndent。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。