Complete the code to declare a string variable named greeting.
val greeting: String = [1]In Kotlin, string literals must be enclosed in double quotes. So "Hello, Kotlin!" is the correct way to assign a string value.
Complete the code to get the length of the string stored in name.
val length = name.[1]The length property returns the number of characters in a Kotlin string.
Fix the error in the code that tries to change a character in a string.
var text = "Kotlin" text[1] = 'C'
Strings in Kotlin are immutable, so you cannot change characters directly. But if you want to access a character, you use square brackets [index]. However, assignment to a character at an index is not allowed.
Fill both blanks to create a new string by replacing the first character of original with 'C'.
val original = "Kotlin" val modified = [1] + original.[2](1)
To replace the first character, we concatenate "C" with the substring of original starting from index 1.
Fill all three blanks to create a new string with all letters uppercase and check if it equals "KOTLIN".
val word = "kotlin" val upperWord = word.[1]() val isEqual = upperWord [2] "KOTLIN" println(isEqual) // prints [3]
The uppercase() function converts the string to uppercase. Then we compare with == to check equality. The result is true because they match.