To check if a string starts with a specific prefix in Kotlin, you can use the 'startsWith' method of the String class.
In this example,
fun startsWithPrefix(str: String, prefix: String): Boolean {
return str.startsWith(prefix)
}
fun main() {
val str = "Hello World"
val prefix = "Hello"
val startsWith = startsWithPrefix(str, prefix)
println("String starts with prefix '$prefix': $startsWith")
}
String starts with prefix 'Hello': true
In this tutorial, we learned How to Check if String starts with Specific Prefix in Kotlin language with well detailed examples.