W3cubDocs

/Kotlin

isNotEmpty

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun CharSequence.isNotEmpty(): Boolean

Returns true if this char sequence is not empty.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
fun markdownLink(title: String, url: String) =
    if (title.isNotEmpty()) "[$title]($url)" else url

// plain link
println(markdownLink(title = "", url = "https://kotlinlang.org")) // https://kotlinlang.org

// link with custom title
println(markdownLink(title = "Kotlin Language", url = "https://kotlinlang.org")) // [Kotlin Language](https://kotlinlang.org)
//sampleEnd
}

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/is-not-empty.html