- Kotlin - Home
- Kotlin - Overview
- Kotlin - Environment Setup
- Kotlin - Architecture
- Kotlin - Basic Syntax
- Kotlin - Comments
- Kotlin - Keywords
- Kotlin - Variables
- Kotlin - Data Types
- Kotlin - Operators
- Kotlin - Booleans
- Kotlin - Strings
- Kotlin - Arrays
- Kotlin - Ranges
- Kotlin - Functions
- Kotlin Control Flow
- Kotlin - Control Flow
- Kotlin - if...Else Expression
- Kotlin - When Expression
- Kotlin - For Loop
- Kotlin - While Loop
- Kotlin - Break and Continue
- Kotlin Collections
- Kotlin - Collections
- Kotlin - Lists
- Kotlin - Sets
- Kotlin - Maps
- Kotlin Objects and Classes
- Kotlin - Class and Objects
- Kotlin - Constructors
- Kotlin - Inheritance
- Kotlin - Abstract Classes
- Kotlin - Interface
- Kotlin - Visibility Control
- Kotlin - Extension
- Kotlin - Data Classes
- Kotlin - Sealed Class
- Kotlin - Generics
- Kotlin - Delegation
- Kotlin - Destructuring Declarations
- Kotlin - Exception Handling
Kotlin String - isBlank() Function
The Kotlin string isBlank() function is used to check whether a string is empty or contains only whitespace character such as spaces, tabs, or line breaks. This function is particularly useful for validating user input or cleaning up data.
Returns true if the string is empty or contains solely whitespace characters. Otherwise, return false if the string contains at least one non-whitespace character.
Syntax
Following is the syntax of the Kotlin string isBlank() function −
fun isBlank(): Boolean
Parameters
This function does not accepts any parameters.
Return value
This function returns a Boolean value, true if the string is empty or contains solely whitespace character; Otherwise false.
Example 1
Following is the basic example, here how we can use isBlank() with an empty string in Kotlin −
fun main() {
val str = ""
println(str.isBlank())
}
Output
Following is the output −
true
Example 2
Now, let's look at another example of what the isBlank() function returns if the string contains whitespace.
fun main() {
val str = " "
println(str.isBlank())
}
Output
Following is the output −
true
Example 3
let's see what the isBlank() function returns if the string contains non_whitespace character. −
fun main() {
val str = "tutorialspoint"
println(str.isBlank())
}
Output
Following is the output −
false