0
0
Kotlinprogramming~5 mins

String methods (substring, split, trim) in Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A"applebananaorange"
B[",", ",", ","]
C["apple,banana,orange"]
D["apple", "banana", "orange"]
What is the result of " Kotlin ".trim()?
A" Kotlin "
B" Kotlin "
C"Kotlin"
D""
Which substring call extracts "cat" from "concatenate"?
Asubstring(3, 6)
Bsubstring(0, 3)
Csubstring(4, 7)
Dsubstring(5, 8)
What does "one two three".split(" ") produce?
A["one two three"]
B["one", "two", "three"]
C"onetwothree"
D[" ", " "]
If val s = " abc ", what does s.substring(2, 5) return?
A"abc"
B" a"
C"bc "
D" "
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.