In Kotlin, we have the ability to format our text with the help of character escape sequences. When escaped, specific characters such as
n represent an action or command to be performed by the compiler.
Take a look at some of the following escape sequences and their operations:
\nInserts a new line
\tInserts a tab
\rInserts a carriage return
\'Inserts a single quote
\"Inserts a double quote
\\Inserts a backslash
\$Inserts the dollar symbol
When used in text, each backslash,
\, and character will be recognized and evaluated by the compiler. More than one escape sequence can be used in a single String.
One of the most commonly used escape sequences is the
\" as it allows us to cite quotations in a String. Take a look:
print("\"May the Force be with you.\" - Star Wars, 1977")
In the output terminal, we’d see:
"May the Force be with you." - Star Wars, 1977
Try the character escape sequence challenge below to hone your understanding of some of these behaviors.
Help Codey format the code in Challenge.kt using the appropriate character escape sequences on the given String. The final text should look like this:
Dear Learner 👋, I hope you're enjoying the Learn Kotlin course. You've made tremendous progress. Keep going! And remember, "Knowledge is power." (Frances Beacon). With love, Codey
One Rule: You can only use a single print statement. Good luck!
P.S. When you’re ready, move on to the next exercise to review what you’ve learned and see the answer to the above prompt.