Multiline String Literals in Scala

package com.vff.examples
/**
 * Extending App means I can run this class.
 *
 * This example shows how MultilineEscaping works.
 */
object StringLiterals extends App {

  /* This String is multiline - scala understands this from the """
   * and will look for the closing """ for the end of the String. */
  val welcomeMessage = """This is a simple
    multiline example"""

  println(welcomeMessage)

  println("---------") // separate output

  /* This version has the | sign to indicate where margins are and,
   * when combined with stripMargin, results in cleaner output. */
  val messageWithPipes = """This example
    |will have
    |cleaner output"""
  println(messageWithPipes.stripMargin)
}

Output:

This is a simple
    multiline example
---------
This example
will have
cleaner output
Advertisements

One thought on “Multiline String Literals in Scala

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s