Scala Raw Rows: Extra Tabs at the Beginning of Each Row

I use raw lines, but when I print a line, I get additional tabs at the beginning of each line.

val rawString = """here is some text
and now im on the next line
and this is the thrid line, and we're done"""

println(rawString)

it outputs

here is some text
    and now im on the next line
    and this is the thrid line, and we're done

I tried to set different line endings, but this did not affect. I am working on a Mac (OS X tiger) using jEdit as my editor. I get the same result when I run the script in the scala interpreter or when I write the output to a file.

Does anyone know what is going on here?

+3
source share
1 answer

, . , scala> + , , , .

scala> val rawString = """here is some text          // new line
     | and now im on the next line                   // scala adds spaces 
     | and this is the thrid line, and we're done""" // to line things up
// note that the comments would be included in a raw string...
// they are here just to explain what happens

rawString: java.lang.String =
here is some text
       and now im on the next line
       and this is the thrid line, and we're done

// you can see that the string produced by the interpreter
// is aligned with the previous spacing, but without the pipe

Scala script scala filename.scala, .

:

val rawString = """|here is some text
                   |and now im on the next line
                   |and this is the thrid line, and we're done""".stripMargin

println(rawString)

stripMargin , | .

EDIT: Scala - extempore:)

: trunk. extempore:).

, :)

-

+11

Source: https://habr.com/ru/post/1727493/


All Articles