Unfortunately stripIndent on a multiline string does not work. Side note: My IDE code style preferences allow only space indentation (tabs will be replaced by spaces). But i
stripMargin() is to strip leading spaces from lines with margin.
Default margin is |
. We can also specify a custom margin.
For example,
def s = """*This
*is
*multiline
"""
println(s.stripMargin("*"))
will result in
This
is
multiline
The best practice is that we append .trim() in the end to eliminate leading and trailing spaces of the whole string.
For example,
println(s.stripMargin("*").trim())