如何解释多行scala字符串中的转义序列?
发布时间:2020-12-16 18:24:15 所属栏目:安全 来源:网络整理
导读:简而言之: """I want to be able to |have the convenient formatting of a multiline string,|while using inline escape sequencesrrb | |How can this be done?""".stripMargin 解决方法 我能想到的两个选择: 您可以直接使用StringContext.treatEs
简而言之:
"""I want to be able to |have the convenient formatting of a multiline string,|while using inline escape sequencesrrb | |How can this be done?""".stripMargin 解决方法
我能想到的两个选择:
>您可以直接使用StringContext.treatEscapes: StringContext.treatEscapes("""I want to be able to |have the convenient formatting of a multiline string,|while using inline escape sequencesrrb | |How can this be done?""".stripMargin) >如果“简单插补器”的变量替换功能不会对您的需求造成干扰,那么尝试将string interpolation(将转义的转义字符转换为)与“”引号(不会转义……)组合: println("""helonworld""") println(s"""helonworld""") 输出 helonworld helo world 有关详细信息,请参阅relevant SIP和this earlier question. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |