【问题标题】:How does one specify multi-line strings in Typesafe Config?如何在 Typesafe Config 中指定多行字符串?
【发布时间】:2016-11-11 16:16:23
【问题描述】:

我有以下配置文件,我想从 Scala 应用this library 使用:

P11 {
    yes="0.0"
    no="1.0"
}

P12 {
    yes="0.01"
    no="0.99"
}

P13 {
id = "123 567 \
T 0: \
If (f 23 <= 0.0)"
}

这就是我的做法:

import com.typesafe.config.ConfigFactory

val configFileName = "/usr/develop/tests/config.conf"
val parsedConfigMCF = ConfigFactory.parseFile(new File(configFileName))
val confMCF = ConfigFactory.load(parsedConfigMCF)

然后我得到错误:

Expecting a value but got wrong token: 'newline' (backslash followed by 'newline', this is not a valid escape sequence

它看起来不像\(反斜杠),但我需要在P13 中为id 添加几行。

【问题讨论】:

    标签: typesafe-config


    【解决方案1】:

    来自 Typesafe Config 的 official documentation

    在 Python 或 Scala 中使用三引号的多行字符串

    所以:

    P13 {
      id = """123 567
      T 0:
      If (f 23 <= 0.0)"""
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-02
      • 1970-01-01
      • 2021-05-14
      • 1970-01-01
      • 2022-11-13
      • 2014-08-29
      • 2014-03-11
      • 2019-04-02
      相关资源
      最近更新 更多