Complete the code to get the substring "Hello" from the string.
val text = "Hello, World!" val sub = text.[1](0, 5) println(sub)
The substring method extracts a part of the string from index 0 to 5 (exclusive), giving "Hello".
Complete the code to split the string into words using space as separator.
val sentence = "Kotlin is fun" val words = sentence.[1](" ") println(words.joinToString(", "))
The split method divides the string into parts using the space character, resulting in a list of words.
Fix the error in the code to remove spaces from the start and end of the string.
val raw = " Kotlin " val clean = raw.[1]() println("'$clean'")
The trim method removes spaces from the start and end of the string, cleaning it up.
Fill both blanks to get the last word from the sentence.
val sentence = "Learn Kotlin easily" val words = sentence.[1](" ") val lastWord = words[[2]] println(lastWord)
First, split divides the sentence into words. Then, index 2 accesses the last word "easily".
Fill all three blanks to extract "Kotlin" from the string with spaces.
val raw = " Learn Kotlin " val clean = raw.[1]() val words = clean.[2](" ") val word = words[[3]] println(word)
First, trim removes spaces around the string. Then, split breaks it into words. Finally, index 1 selects "Kotlin".