如果我使用以下常规代码:
description: '''Join the Perl programmers of the Pork Producers
of America as we hone our skills and ham it up
a bit. You can show off your programming chops
while trying to win a year's supply of pork
chops in our programming challenge.
Come and join us in historic (and aromatic),
Austin, Minnesota. You'll know when you're
there!'''
groovy 不是应该创建一个长字符串,行之间只有一个空格(意味着行之间的空格不会被保留)吗?结果字符串将是:
加入美国 pig 肉生产商协会的 Perl 程序员,我们磨练我们的技能并增强它......等等
我得到的字符串包含行之间的所有空格。这是预期的行为吗?
最佳答案
自 Groovy 1.7.3 起:
def description = '''\
Join the Perl programmers of the Pork Producers
of America as we hone our skills and ham it up
a bit. You can show off your programming chops
while trying to win a year's supply of pork
chops in our programming challenge.
Come and join us in historic (and aromatic),
Austin, Minnesota. You'll know when you're
there!'''.stripIndent()
关于grails - Groovy 中的三重单引号字符串 - 结果字符串是否应该包含额外的空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1529232/