如何在scala的heredoc中绑定数据? [英] How to bind data in heredoc of scala?
本文介绍了如何在scala的heredoc中绑定数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
val name = "mike"
val str = """Hi, {name}!"""
println(str)
我希望它输出 str 为 Hi,mike!
,但失败了.如何做到这一点?
I want it output the str as Hi, mike!
, but failed. How to do this?
推荐答案
Scala 不支持字符串插值.有一个编译器插件可以在 http://github.com/jrudolph/scala-enhanced-字符串.
Scala does not support string interpolation. There is a compiler plugin that implements it at http://github.com/jrudolph/scala-enhanced-strings.
如果没有插件,您可以使用连接或格式字符串:
Without the plugin you can use concatenation or format strings:
val str = name formatted "Hi, %s!"
或者当然
val str = "Hi, %s!".format(name)
这篇关于如何在scala的heredoc中绑定数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文