-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
  • 11,477
  • 4
  • 47
  • 66
Sodiaan
  • 311
  • 1
  • 2
  • 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
  • 32,979
  • 19
  • 111
  • 146
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
  • 67,502
  • 14
  • 150
  • 189