0
0
Kotlinprogramming~10 mins

Multiline strings with trimIndent in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a multiline string using triple quotes.

Kotlin
val text = [1]
    Hello, Kotlin!
    Welcome to multiline strings.
"""
Drag options to blanks, or click blank then click option'
A"
B"""
C'
D`
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes instead of triple quotes.
Using backticks which are for identifiers, not strings.
2fill in blank
medium

Complete the code to remove leading indentation from the multiline string.

Kotlin
val text = """
    Kotlin is fun.
    Let's learn together.
""".[1]()
Drag options to blanks, or click blank then click option'
AtrimIndent
BtrimStart
CtrimMargin
DtrimEnd
Attempts:
3 left
💡 Hint
Common Mistakes
Using trimMargin() which requires a margin prefix.
Using trimStart() or trimEnd() which only trim spaces at start or end of the whole string.
3fill in blank
hard

Fix the error in the code to correctly trim indentation from the multiline string.

Kotlin
val message = """
        Welcome to Kotlin!
        Enjoy coding.
    """.[1]()
Drag options to blanks, or click blank then click option'
AtrimMargin
BstripIndent
Ctrim
DtrimIndent
Attempts:
3 left
💡 Hint
Common Mistakes
Using trimMargin() without margin prefix causes no effect.
Using trim() only removes spaces at start and end of whole string.
4fill in blank
hard

Fill both blanks to create a multiline string and remove its indentation.

Kotlin
val poem = [1]
    Roses are red,
    Violets are blue.
""".[2]()
Drag options to blanks, or click blank then click option'
A"""
BtrimMargin
CtrimIndent
Dtrim
Attempts:
3 left
💡 Hint
Common Mistakes
Using trimMargin() without margin prefix.
Not using triple quotes for multiline strings.
5fill in blank
hard

Fill all three blanks to create a multiline string, trim indentation, and print it.

Kotlin
fun main() {
    val quote = [1]
        Be yourself;
        everyone else is already taken.
    """.[2]()
    println([3])
}
Drag options to blanks, or click blank then click option'
A"""
BtrimIndent
Cquote
DtrimMargin
Attempts:
3 left
💡 Hint
Common Mistakes
Using trimMargin() without margin prefix.
Printing the string literal instead of the variable.
Not using triple quotes for multiline strings.