- 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
推薦閱讀
- 深入理解Android(卷I)
- Monkey Game Development:Beginner's Guide
- Java面向對象思想與程序設計
- Visual C++串口通信技術詳解(第2版)
- SQL Server與JSP動態網站開發
- Visual Basic 6.0程序設計實驗教程
- C語言程序設計實訓教程與水平考試指導
- Advanced UFT 12 for Test Engineers Cookbook
- Visual Basic程序設計(第三版)
- SQL Server 2008中文版項目教程(第3版)
- Java 11 and 12:New Features
- Python面向對象編程(第4版)
- Learning NHibernate 4
- Mastering PostgreSQL 11(Second Edition)
- Switching to Angular 2