- Learning Scala Programming
- Vikash Sharma
- 143字
- 2021-06-30 19:07:53
String Interpolators
We've already used String Interpolators, it's hard to avoid using them when they are available to you. Remember when we used them? Yes! When we were learning to create operators on our own:
println(s"Total Amount for order:: ${amountAfterTax(new Amount(firstOrderAmount))}")
This little s here is a String interpolator. While using these, we precede our String with a character named s, and inside double quotes of the String, we can use any variable with a $ and it'll be replaced by its value:
scala> val myAge = s"I completed my $age."
myAge: String = I completed my 25.
This is an example of how we can use interpolators. The s is not the only interpolator existing in Scala. We have a couple more interpolators. We'll go through them one by one.
- The s interpolator
- The f interpolator
- The raw interpolator
推薦閱讀
- VMware View Security Essentials
- 精通JavaScript+jQuery:100%動態網頁設計密碼
- ASP.NET MVC4框架揭秘
- GeoServer Cookbook
- C# Programming Cookbook
- Building a Recommendation Engine with Scala
- iOS開發實戰:從入門到上架App Store(第2版) (移動開發叢書)
- Linux C編程:一站式學習
- Lighttpd源碼分析
- Exploring SE for Android
- HTML5移動Web開發
- jQuery Mobile Web Development Essentials(Second Edition)
- 3ds Max 2018從入門到精通
- Java程序設計教程
- Python繪圖指南:分形與數據可視化(全彩)