I’m using a raw strings but when I print the string I’m getting extra tabs at the start 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)
this outputs
here is some text
and now im on the next line
and this is the thrid line, and we're done
I’ve tried setting different line endings but that had no effect.
I’m working on the 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 file.
Anybody know whats going on here?
This problem is due to the fact that you are using multiline raw strings in the interpreter. You can see that the width of the extra spaces is exactly the size of the
scala>prompt or the size of the pipe + spaces added by the interpreter when you create a new line in order to keep things lined up.If you write your code in a Scala script and run it as
scala filename.scalayou do not get the extra tabs.Alternatively, you can use the following construct in the interpreter:
What
stripMargindoes is strips anything before and including the|character at the start of every line in the raw string.EDIT: This is a known Scala bug — thanks extempore 🙂
UPDATE: Fixed in trunk. Thanks extempore again :).
Hope it helps 🙂
— Flaviu Cipcigan