grails - Groovy 中的三重单引号字符串 - 结果字符串是否应该包含额外的空格?

标签 grails groovy

如果我使用以下常规代码:

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/

相关文章:

tomcat - 在 Tomcat 中完全取消部署 Grails 应用程序

grails - 如何在Grails Controller 中调用方法而不渲染新 View ?

grails - 在哪里指定了grails库

unit-testing - 如何在Grails测试中填充有效参数

testing - soapUI:如何从断言脚本访问测试步骤属性?

json - Grails 无法将 JSON 数组转换为 HashMap

maven - 无法使用Maven执行wsdl2java

grails - 建立一对多对一的关系

grails - 在grails的taglib定义内使用资源?

regex - 使用groovy中的正则表达式从字符串中提取数字