Skip to content

Instantly share code, notes, and snippets.

@Ayeeta
Created August 1, 2020 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ayeeta/b85abbf9c459e4f6d835536a2af433bd to your computer and use it in GitHub Desktop.
Save Ayeeta/b85abbf9c459e4f6d835536a2af433bd to your computer and use it in GitHub Desktop.
About strings in kotlin
//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