Created
August 1, 2020 21:02
-
-
Save Ayeeta/b85abbf9c459e4f6d835536a2af433bd to your computer and use it in GitHub Desktop.
About strings in kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Escaped strings, means you can use escaped characters | |
val escapedString = "Kotlin is fun because Zombie said \"Kotlin is ...\" " | |
println(escapedString) | |
/** | |
output - Kotlin is fun because Zombie said "Kotlin is ..." | |
Here's a ist of escape characters you could use | |
\t - Inserts tab | |
\b - Inserts backspace | |
\n - Inserts newline | |
\r - Inserts carriage return | |
\' - Inserts single quote character | |
\" - Inserts double quote character | |
\\ - Inserts backslash | |
\$ - Inserts dollar character **/ | |
//Raw strings, means you cannot use escape characters but """ | |
val rawStringExample = """ | |
This is a raw string | |
You do not have to use | |
the newline escape | |
character | |
""" | |
println(rawStringExample) | |
//More on string literals with variables | |
val zombie = "Zombie apocalyps" | |
val zombieStartDate = "32nd May, 2020" | |
println("The ${zombie.toUpperCase()} will start on ${zombieStartDate} and will go for ${1-2} years") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment