我想在使用heredoc时保留源文件中的预期缩进,但同时,在渲染时,此文档的内容不会缩进.例如以下内容
// myscript.groovy
if ( someCondition ) {
println """
some multi-line
content
"""
}
Run Code Online (Sandbox Code Playgroud)
将打印缩进的输出,例如
$ groovy myscript.groovy
some multi-line
content
Run Code Online (Sandbox Code Playgroud)
但我希望它只是打印未缩进的内容,如下所示
$ groovy myscript.groovy
some multi-line
content
Run Code Online (Sandbox Code Playgroud)
如何在Groovy中实现这一目标?
Bash有<<-STRINGheredoc定义来完成这个,但是我找不到任何类似的Groovy.
你需要stripMargin
if ( someCondition ) {
println """
|some multi-line
|content
|""". stripMargin()
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2133 次 |
| 最近记录: |