Chapter 3 Code Sample

Looks like this code snippet is Swift instead of Kotlin :grin:

let bigString = """
  |You can have a string
  |that contains multiple
  |lines
  |by
  |doing this.
  """.trimMargin()
println(bigString)

To fix, change it to:

val bigString = """
  |You can have a string
  |that contains multiple
  |lines
  |by
  |doing this.
  """.trimMargin()
println(bigString)
1 Like

In the explanation for the above code, they mention the pipe (|) and the function trimMargin(), but the explanation doesnโ€™t quite jive with the actual code. i.e., indentation can be achieved without using the pipe at all, so itโ€™s not at clear what effect, if any, the pipe is achieving.

1 Like

Great catch! Thank you so much for reporting this, we really appreciate it.

I have submitted the let to val fix to our editor, as well as an updated explanation copied below. Please let me know what you think!

The three double-quotes signify that this is a multi-line string. Handily, trimMargin() will remove new lines at the beginning and end of the string to remove unnecessary white space. This way, you are not forced to put the """ on the same line as the string. Finally, the | character (known as a โ€œpipeโ€) ensures that all preceding white space from each line is removed, giving you more flexibility in indentation without affecting the output.

1 Like

sounds great, thanks!

1 Like