Home > database >  How to embed a triple double quote in a raw string
How to embed a triple double quote in a raw string

Time:03-16

Suppose we have a raw string as follows:

val myRawString = """line 1
line2
line3"""

Suppose the value we want to represent as a raw string has a line which itself contains a triple double quote. For instance, line4 should be this line has """ (triple double quote) How can we accomplish that?

CodePudding user response:

One way that I've seen mentioned in a similar question on the Kotlin slack was to declare a variable:

val qqq = "\"\"\""
val myRawString = """line 1
line2
line3
this line has $qqq (triple double quote)"""

CodePudding user response:

You cannot escape anything in a raw string, but you can use string templates, and you can escape inside those, so you could do this:

val myRawString = """line 1
line2
line3
this line has ${"\"\"\""} (triple double quote)
"""
  • Related