isWhitespace
Determines whether a character is whitespace.
A character is considered whitespace if either its Unicode category is one of CharCategory.SPACE_SEPARATOR, CharCategory.LINE_SEPARATOR, CharCategory.PARAGRAPH_SEPARATOR, or it is a CharCategory.CONTROL character in range U+0009..U+000D
or U+001C..U+001F
.
Returns true
if the character is whitespace.
Since Kotlin
1.0Samples
import java.util.*
import kotlin.test.*
fun main() {
//sampleStart
val chars = listOf(' ', '\t', '\n', '1', 'a', '\u00A0')
val (whitespaces, notWhitespaces) = chars.partition { it.isWhitespace() }
// whitespace char codes
println(whitespaces.map(Char::code)) // [32, 9, 10, 160]
// non-whitespace chars
println(notWhitespaces) // [1, a]
//sampleEnd
}
Determines whether a character is whitespace.
A character is considered whitespace if either its Unicode category is one of CharCategory.SPACE_SEPARATOR, CharCategory.LINE_SEPARATOR, CharCategory.PARAGRAPH_SEPARATOR, or it is a CharCategory.CONTROL character in range U+0009..U+000D
or U+001C..U+001F
.
Returns true
if the character is whitespace.
Since Kotlin
1.1Samples
import java.util.*
import kotlin.test.*
fun main() {
//sampleStart
val chars = listOf(' ', '\t', '\n', '1', 'a', '\u00A0')
val (whitespaces, notWhitespaces) = chars.partition { it.isWhitespace() }
// whitespace char codes
println(whitespaces.map(Char::code)) // [32, 9, 10, 160]
// non-whitespace chars
println(notWhitespaces) // [1, a]
//sampleEnd
}
Determines whether a character is whitespace.
A character is considered whitespace if either its Unicode category is one of CharCategory.SPACE_SEPARATOR, CharCategory.LINE_SEPARATOR, CharCategory.PARAGRAPH_SEPARATOR, or it is a CharCategory.CONTROL character in range U+0009..U+000D
or U+001C..U+001F
.
Returns true
if the character is whitespace.
Since Kotlin
1.0Samples
import java.util.*
import kotlin.test.*
fun main() {
//sampleStart
val chars = listOf(' ', '\t', '\n', '1', 'a', '\u00A0')
val (whitespaces, notWhitespaces) = chars.partition { it.isWhitespace() }
// whitespace char codes
println(whitespaces.map(Char::code)) // [32, 9, 10, 160]
// non-whitespace chars
println(notWhitespaces) // [1, a]
//sampleEnd
}
Determines whether a character is whitespace.
A character is considered whitespace if either its Unicode category is one of CharCategory.SPACE_SEPARATOR, CharCategory.LINE_SEPARATOR, CharCategory.PARAGRAPH_SEPARATOR, or it is a CharCategory.CONTROL character in range U+0009..U+000D
or U+001C..U+001F
.
Returns true
if the character is whitespace.
Since Kotlin
1.3Samples
import java.util.*
import kotlin.test.*
fun main() {
//sampleStart
val chars = listOf(' ', '\t', '\n', '1', 'a', '\u00A0')
val (whitespaces, notWhitespaces) = chars.partition { it.isWhitespace() }
// whitespace char codes
println(whitespaces.map(Char::code)) // [32, 9, 10, 160]
// non-whitespace chars
println(notWhitespaces) // [1, a]
//sampleEnd
}
Determines whether a character is whitespace.
A character is considered whitespace if either its Unicode category is one of CharCategory.SPACE_SEPARATOR, CharCategory.LINE_SEPARATOR, CharCategory.PARAGRAPH_SEPARATOR, or it is a CharCategory.CONTROL character in range U+0009..U+000D
or U+001C..U+001F
.
Returns true
if the character is whitespace.
Since Kotlin
1.8Samples
import java.util.*
import kotlin.test.*
fun main() {
//sampleStart
val chars = listOf(' ', '\t', '\n', '1', 'a', '\u00A0')
val (whitespaces, notWhitespaces) = chars.partition { it.isWhitespace() }
// whitespace char codes
println(whitespaces.map(Char::code)) // [32, 9, 10, 160]
// non-whitespace chars
println(notWhitespaces) // [1, a]
//sampleEnd
}
Determines whether a character is whitespace.
A character is considered whitespace if either its Unicode category is one of CharCategory.SPACE_SEPARATOR, CharCategory.LINE_SEPARATOR, CharCategory.PARAGRAPH_SEPARATOR, or it is a CharCategory.CONTROL character in range U+0009..U+000D
or U+001C..U+001F
.
Returns true
if the character is whitespace.
Since Kotlin
1.8Samples
import java.util.*
import kotlin.test.*
fun main() {
//sampleStart
val chars = listOf(' ', '\t', '\n', '1', 'a', '\u00A0')
val (whitespaces, notWhitespaces) = chars.partition { it.isWhitespace() }
// whitespace char codes
println(whitespaces.map(Char::code)) // [32, 9, 10, 160]
// non-whitespace chars
println(notWhitespaces) // [1, a]
//sampleEnd
}