To convert a string to lowercase in Kotlin, you can use the toLowerCase()
function of the String class.
In this example,
str1
with the value "Hello World"
.toLowerCase()
on str1
and store the result in lowercaseStr1
.lowercaseStr1
to the console.// Convert "Hello World" to Lowercase
fun main() {
val str1 = "Hello World"
val lowercaseStr1 = str1.toLowerCase()
println("Lowercase: $lowercaseStr1")
}
Lowercase: hello world
In this example,
str2
with the value "Kotlin Programming"
.toLowerCase()
on str2
and store the result in lowercaseStr2
.lowercaseStr2
to the console.// Convert "Kotlin Programming" to Lowercase
fun main() {
val str2 = "Kotlin Programming"
val lowercaseStr2 = str2.toLowerCase()
println("Lowercase: $lowercaseStr2")
}
Lowercase: kotlin programming
In this tutorial, we learned How to convert String to Lowercase in Kotlin language with well detailed examples.