-2

In many languages multiline String literal syntax is

"""
Hello
World
"""

But why it require a new syntax, why just not to use " instead of """ ?

Like:

"Hello
 World"
Salem
  • 13,516
  • 4
  • 51
  • 70
Sodiaan
  • 341
  • 1
  • 3
  • 10

2 Answers2

9

I think this is primarily to allow nested double quotes:

"""
Hello, "World"
"""

If " was used for multiline strings, then you had to escape nested quotes which is a bit inconvenient.

ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
3

You can simply include formatted code like this:

val text = """
    for (c in "foo")
        print(c)
"""

or use special chars like " without the need to escape. It's very neat when it comes to JSON for example.

s1m0nw1
  • 76,759
  • 17
  • 167
  • 196