# Idiomatic way to embed three double quotes in a triple quoted / multiline string

**URL:** <https://discuss.kotlinlang.org/t/idiomatic-way-to-embed-three-double-quotes-in-a-triple-quoted-multiline-string/29801>\
**Category:** Language Design\
**Created:** [January 26, 2025, 10:33am UTC](https://discuss.kotlinlang.org/t/idiomatic-way-to-embed-three-double-quotes-in-a-triple-quoted-multiline-string/29801 "2025-01-26T10:33:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikclayton](https://avatars.discourse-cdn.com/v4/letter/n/67e7ee/32.png) [@nikclayton](https://discuss.kotlinlang.org/u/nikclayton)\
**Post date:** [January 26, 2025, 10:33am UTC](https://discuss.kotlinlang.org/t/idiomatic-way-to-embed-three-double-quotes-in-a-triple-quoted-multiline-string/29801/1 "2025-01-26T10:33:50Z")

</div>

There doesn’t seem to be a mechanism to embed `"""` in a triple-quoted string that doesn’t involve interpolation. I.e.:

```kotlin
val tq = "\"\"\""
val s = """
This string needs to contain triple quotes, like this: $tq
"""

```

Obviously, this works, but feels a little awkward. It’s even more awkward if you’re writing a regex as a triple quoted string, but `"""` is part of the thing you want to match (work around: `"{3}` in the regex).

Anyone got anything cleaner?

---

<div class="post-metadata">

**Author:** ![hybridion](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hybridion](https://discuss.kotlinlang.org/u/hybridion)\
**Post date:** [February 3, 2025, 9:38pm UTC](https://discuss.kotlinlang.org/t/idiomatic-way-to-embed-three-double-quotes-in-a-triple-quoted-multiline-string/29801/2 "2025-02-03T21:38:53Z")

</div>

Multiline strings don’t support escaping (by design), so interpolation is going to be the only option.

Arguably only slightly less cumbersome in some cases (and less indirection), you could avoid the val (if you’re not going to use it a bunch of times) like so:

```auto
val s = """
    This string needs to contain triple quotes, like this: ${"\"\"\""}
"""

```

---

<div class="post-metadata">

**Author:** ![sken130](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@sken130](https://discuss.kotlinlang.org/u/sken130)\
**Post date:** [June 12, 2025, 7:47am UTC](https://discuss.kotlinlang.org/t/idiomatic-way-to-embed-three-double-quotes-in-a-triple-quoted-multiline-string/29801/3 "2025-06-12T07:47:49Z")

</div>

See this Youtrack issue.  
[Provide a way to escape 3 or more consecutive double quotes : KT-67058](https://youtrack.jetbrains.com/issue/KT-67058/Provide-a-way-to-escape-3-or-more-consecutive-double-quotes)
