String interpolation in Scala 2.10 - How to interpolate a String variable?

前端 未结 4 1451
面向向阳花
面向向阳花 2020-12-02 22:11

String interpolation is available in Scala starting Scala 2.10

This is the basic example

 val name = \"World\"            //> name  : String = W         


        
4条回答
  •  被撕碎了的回忆
    2020-12-02 22:59

    Here is a possible solution to #1 in the context of the original question based on Rex's excellent answer

    val name = "World"                  //> name: String = World
    val template = name=>s"Hello $name" //> template: Seq[Any]=>String = 
    val message = template(name)        //> message: String = Hello World
    

提交回复
热议问题