scala multiline string

In Scala, you can create multiline strings using triple quotes ("""). This allows you to include line breaks and special characters without the need for explicit escape sequences.

Here's an example of a multiline string in Scala:

val multilineString = """
  This is a
  multiline
  string.
"""

println(multilineString)

The output will be:

  This is a
  multiline
  string.

You can also use the stripMargin method to remove leading whitespace from each line in the multiline string. By default, it uses the pipe character (|) as the margin character:

val multilineString = """
  |This is a
  |multiline
  |string.
""".stripMargin

println(multilineString)

The output will be:

This is a
multiline
string.

You can also specify a different margin character by passing it as an argument to the stripMargin method. For example, if you want to use the tilde character (~) as the margin character, you can do:

val multilineString = """
  ~This is a
  ~multiline
  ~string.
""".stripMargin('~')

println(multilineString)

The output will be:

This is a
multiline
string.

Keep in mind that the leading whitespace before the margin character is considered part of the margin and will be removed.