String functions in Kotlin Part – 2

contains: This function returns true if the string contains a specified substring.

val str = "Hello, World!"
println(str.contains("World")) // Output: true
println(str.contains("Kotlin")) // Output: false

startsWith/endsWith: These functions return true if the string starts with or ends with a specified substring.

val str = "Hello, World!"
println(str.startsWith("Hello")) // Output: true
println(str.endsWith("World!")) // Output: true

split: This function splits the string into an array of substrings based on a specified delimiter.

val str = "The quick brown fox jumps over the lazy dog"
val words = str.split(" ")
println(words) // Output: [The, quick, brown, fox, jumps, over, the, lazy, dog]

toInt/toDouble: These functions convert the string to an integer or a double.

val str = "42"
val num = str.toInt()
println(num) // Output: 42