0
0
Kotlinprogramming~15 mins

Multiline strings with trimIndent in Kotlin - Mini Project: Build & Apply

Choose your learning style9 modes available
Multiline strings with trimIndent
📖 Scenario: You are creating a simple Kotlin program to display a formatted message using multiline strings. Multiline strings help keep text readable and maintain the intended layout.
🎯 Goal: Build a Kotlin program that uses a multiline string with trimIndent() to remove extra indentation and print a clean, formatted message.
📋 What You'll Learn
Create a multiline string variable with indented text
Use trimIndent() to remove common leading whitespace
Print the cleaned multiline string
💡 Why This Matters
🌍 Real World
Multiline strings with trimIndent are useful for writing formatted text blocks like messages, SQL queries, or JSON in Kotlin code without extra spaces.
💼 Career
Understanding multiline strings and trimming indentation helps write cleaner, more readable Kotlin code, a skill valuable for Android and backend Kotlin developers.
Progress0 / 4 steps
1
Create a multiline string variable
Create a multiline string variable called message with the following exact content including indentation: """ Hello, Welcome to Kotlin programming! Enjoy learning. """
Kotlin
Need a hint?

Use triple quotes """ to start and end the multiline string.

2
Apply trimIndent() to the multiline string
Add trimIndent() to the message variable to remove the common leading whitespace from each line.
Kotlin
Need a hint?

Call trimIndent() immediately after the multiline string.

3
Print the trimmed multiline string
Write a println statement to print the message variable.
Kotlin
Need a hint?

Use println(message) to display the text.

4
Run and verify the output
Run the program and verify that the output matches exactly: Hello, Welcome to Kotlin programming! Enjoy learning.
Kotlin
Need a hint?

The printed text should have no leading spaces on each line.