Convert String to Lowercase in Kotlin
To convert a given string to a lowercase string in Kotlin, you can use String.toLowerCase() function.
Call toLowerCase() function on the given String object str.
str.toLowerCase()
toLowerCase() function returns a new string created from converting all the characters of the calling string to lowercase.
Examples
Convert given string to lowercase
Consider a scenario where we are given a string, say "Hello World" in a variable str. We need to convert the characters in this string to their lowercase, and print the resulting string.
Kotlin Program
fun main() {
val str = "Hello World"
val lowercaseString = str.toLowerCase()
println(lowercaseString)
}
Output
hello world