【问题标题】:Escaping in groovy在常规中逃脱
【发布时间】:2012-10-29 12:04:28
【问题描述】:

在 groovy 中我需要帮助

我在这样的文本文件中有一些字符串 #$commonTomcat620.max_threads$# 这些值我必须在运行时替换。

我使用了以下代码:

    def str = "#\$commonTomcat620.max_threads\$#"
    fileContents = fileContents.replaceAll("${str}","100");

这个 str 在值中打印为 #$commonTomcat620.max_threads$#。但不替换文件。我试过 withOut #$ 。这是工作。

谢谢。

【问题讨论】:

    标签: groovy escaping


    【解决方案1】:

    你有几个选择来逃避美元符号:

    这有效(使用美元斜线):

    def str = $/#\$$commonTomcat620.max_threads\$$#/$
    

    或者这个(单引号字符串):

    def str = '#\\$commonTomcat620.max_threads\\$#'
    

    其他选项可能也存在

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-24
      • 1970-01-01
      • 1970-01-01
      • 2017-10-31
      • 2016-02-11
      • 1970-01-01
      • 2012-08-21
      • 1970-01-01
      相关资源
      最近更新 更多