Recall & Review
beginner
What does the
substring method do in Kotlin?It extracts a part of a string from a start index up to, but not including, an end index, returning a new string.
Click to reveal answer
beginner
How does the
split method work on a string?It divides the string into parts based on a delimiter and returns a list of substrings.
Click to reveal answer
beginner
What is the purpose of the
trim method in Kotlin strings?It removes any whitespace characters from the start and end of the string.
Click to reveal answer
beginner
Given
val text = " Hello Kotlin ", what does text.trim() return?It returns the string "Hello Kotlin" without the spaces at the start and end.
Click to reveal answer
beginner
How would you get the substring "Kotlin" from
val text = "Hello Kotlin"?Use
text.substring(6) to get "Kotlin" starting from index 6 to the end.Click to reveal answer
What does
"apple,banana,orange".split(",") return?✗ Incorrect
The split method divides the string at each comma, returning a list of the parts.
What is the result of
" Kotlin ".trim()?✗ Incorrect
Trim removes spaces from the start and end, leaving just "Kotlin".
Which substring call extracts "cat" from "concatenate"?
✗ Incorrect
Characters at indexes 3 to 5 are 'c', 'a', 't' which form "cat".
What does
"one two three".split(" ") produce?✗ Incorrect
Splitting by space divides the string into words.
If
val s = " abc ", what does s.substring(2, 5) return?✗ Incorrect
Indexes 2 to 4 are 'a', 'b', 'c', so substring returns "abc".
Explain how to use substring, split, and trim methods on strings in Kotlin with simple examples.
Think about cutting, breaking, and cleaning a string.
You got /4 concepts.
Describe a real-life situation where you might use split and trim methods together on a string.
Imagine cleaning and breaking a sentence typed by a user.
You got /3 concepts.