- Learn Kotlin Programming(Second Edition)
- Stephen Samuel Stefan Bocutiu
- 170字
- 2021-06-24 14:13:27
String templates
String templates are a simple and effective way of embedding values, variables, or even expressions inside a string without the need for pattern replacement or string concatenation. Many languages now support this kind of feature, and Kotlin's designers also opted to include it (you might see the technique referred to in the Kotlin context as string interpolation).
String templates improve on the Java experience when using multiple variables in a single literal, as it keeps the string short and more readable.
Java developers will be familiar with the usage of string concatenation to mix expressions with string literals:
val name = "Sam" val concat = "hello " + name
Usage is extremely straightforward. A value or variable can be embedded simply by prefixing with a dollar ($) symbol:
val name = "Sam" val str = "hello $name"
Arbitrary expressions can be embedded by prefixing with a dollar ($) symbol and wrapping, in braces ({}):
val name = "Sam" val str = "hello $name. Your name has ${name.length} characters"
- iOS開發實戰:從零基礎到App Store上架
- 精通軟件性能測試與LoadRunner實戰(第2版)
- 64位匯編語言的編程藝術
- PHP網絡編程學習筆記
- 深入淺出DPDK
- Python數據分析從0到1
- 名師講壇:Spring實戰開發(Redis+SpringDataJPA+SpringMVC+SpringSecurity)
- Python數據結構與算法(視頻教學版)
- Angular開發入門與實戰
- Learning Ionic
- Software-Defined Networking with OpenFlow(Second Edition)
- Python數據科學實踐指南
- Scratch編程從入門到精通
- Linux Networking Cookbook
- Visual C++ 開發從入門到精通