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
As @stefanglase mentioned I use .stripIndent()
combined with .trim()
:
String mystring = """
My multiline
string
contains blank lines
at the beginning and the end
"""
print "*${mystring.stripIndent()}*"
print "*${mystring.stripIndent().trim()}*"
>*
>My multiline
> string
>contains blank lines
> at the beginning and the end
>*
>*My multiline
> string
>contains blank lines
> at the beginning and the end*