Scala 中的字符串插值? [英] String interpolation in Scala?

查看:48
本文介绍了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

这篇关于Scala 中的字符串插值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆