原创转载请注明出处:http://agilestyle.iteye.com/blog/2333300
利用字符创插值,你创建的字符串就可以包含格式化的值。
在字符串的前面放置一个s,在你想让Scala插值的标识符之前放置一个$
package org.fool.scala.strings
case class Sky(color: String)
object StringInterpolation extends App {
def print(s: String, n: Int, d: Double): String = s"first: $s, second: $n, third: $d"
println(print("Hello", 3, 0.14))
def f(n: Int): Int = n * 2
println(s"f(2) is ${f(2)}")
println(s"${Sky("blue")}")
}
Console Output

本文介绍Scala语言中字符串插值的使用方法,通过示例展示了如何将变量和表达式的值嵌入到字符串中,同时提供了简单的案例来说明其用法。
360

被折叠的 条评论
为什么被折叠?



