toBooleanStrict

Common
JVM
JS
Native
1.5
fun String.toBooleanStrict(): Boolean

Returns true if the content of this string is equal to the word "true", false if it is equal to "false", and throws an exception otherwise.

There is also a lenient version of the function available on nullable String, String?.toBoolean. Note that this function is case-sensitive.

import java.util.Locale
import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
println("true".toBooleanStrict()) // true
// "True".toBooleanStrict() //  will fail
// "TRUE".toBooleanStrict() //  will fail

println("false".toBooleanStrict()) // false
// "False".toBooleanStrict() //  will fail
// "FALSE".toBooleanStrict() //  will fail

// "abc".toBooleanStrict() //  will fail
//sampleEnd
}