- 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
推薦閱讀
- Flutter開發實戰詳解
- Machine Learning with R Cookbook(Second Edition)
- 面向STEM的Scratch創新課程
- x86匯編語言:從實模式到保護模式(第2版)
- Getting Started with SQL Server 2012 Cube Development
- Visual C#通用范例開發金典
- Learning Probabilistic Graphical Models in R
- Protocol-Oriented Programming with Swift
- C++反匯編與逆向分析技術揭秘(第2版)
- Building Serverless Web Applications
- 監控的藝術:云原生時代的監控框架
- 交互設計師成長手冊:從零開始學交互
- Android嵌入式系統程序開發(基于Cortex-A8)
- 從零開始學UI設計·基礎篇
- Perl 6 Deep Dive