Scala 中的字符串插值?

问题描述:

我想问一下 Scala 中是否有任何类型的字符串插值.我已经对这个主题进行了搜索,但直到现在我发现没有字符串插值.是否有计划在下一个版本中实施?

I wanted to ask if there is any type of string interpolation in Scala. I have made a search on the subject but 'till now I have found that there is no string interpolation. Is there plans to get implemented in next versions?

谢谢!

更新

字符串插值将在 scala 2.10 中进行,您可以尝试一下,因为 scala 2.10.RC1 已发布(2012 年 10 月 20 日).您可以查看此 SIP for scala 2.11,其中指出模式匹配器中的内插字符串将是有效的语法.使用新的字符串插值,您可以执行以下操作:

String interpolation is going to be in scala 2.10 which you can try out since scala 2.10.RC1 is out (20/10/2012). You can check out this SIP for scala 2.11 which states that interpolated strings in the pattern matcher will be valid syntax. With the new string interpolation you can do something like this:

val age = 28
val name = "Gerry"

s"My name is $name and I am $age years old"
res0: String = My name is Gerry and I am 28 years old

但是在所有插值器上尝试文档目前可用.请注意,您可以定义自己的插值器!尝试此链接了解更多信息.

But try out the documentation on all the interpolators that are available at the moment. Note that you can define your own interpolators! Try this link for more info.

它还不在(已发布的)scala 库中.但是有一个 SIP(​​Scala 改进过程)用于添加此功能:

It's not in the (released) scala library yet. But there is a SIP (Scala Improvement Process) for the addition of this feature:

http://docs.scala-lang.org/sips/pending/string-interpolation.html