W3cubDocs

/Kotlin

isBlank

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

Returns true if this string is empty or consists solely of whitespace characters.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
fun validateName(name: String): String {
    if (name.isBlank()) throw IllegalArgumentException("Name cannot be blank")
    return name
}

println(validateName("Adam")) // Adam
// validateName("") //  will fail
// validateName("  \t\n") //  will fail
//sampleEnd
}

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