Skip to content

Instantly share code, notes, and snippets.

@kalaiselvan369
Created June 12, 2023 11:17
Show Gist options
  • Save kalaiselvan369/b39568f901cb235fbb1e4865551084e3 to your computer and use it in GitHub Desktop.
Save kalaiselvan369/b39568f901cb235fbb1e4865551084e3 to your computer and use it in GitHub Desktop.
String Template Usage
fun main() {
// various string template options
val n = 10
println("value is $n")
val message = "The value is $n"
println(message)
val result = "The multiple is ${n * 8}"
println(result)
val isNumberEven = "Is number even: ${n % 2 == 0}"
println(isNumberEven)
// escaped strings
// here we are escaping the double quotes by prefixing with backward slash
val quote1 = "\"Newton third law states that for every action there is an equal and opposite reaction\""
println(quote1)
val quote2 = """
>>Life is like a box of chocolates.
>>You never know what you're gonna get - Forrest Gump
""".trimMargin(">>")
println(quote2)
val withoutTrimIndent = """
If you are good at something then don't do it for free - Heath Ledger
Reach to the stars - Unknown
Opportunity is limitless - Unknown
Shine like a star - Unknown
"""
val withTrimIndent = """
If you are good at something then don't do it for free - Heath Ledger
Reach to the stars - Unknown
Opportunity is limitless - Unknown
Shine like a star - Unknown
""".trimIndent()
println(withoutTrimIndent)
println(withTrimIndent)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment