- 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"
- JavaScript從入門到精通(微視頻精編版)
- 自己動手寫搜索引擎
- Mastering Kotlin
- 編寫高質量代碼:改善C程序代碼的125個建議
- Python數據分析(第2版)
- Learn React with TypeScript 3
- Oracle 18c 必須掌握的新特性:管理與實戰
- Nginx實戰:基于Lua語言的配置、開發與架構詳解
- OpenResty完全開發指南:構建百萬級別并發的Web應用
- Java Fundamentals
- C陷阱與缺陷
- Arduino機器人系統設計及開發
- 基于GPU加速的計算機視覺編程:使用OpenCV和CUDA實時處理復雜圖像數據
- Java高并發編程詳解:深入理解并發核心庫
- 數字媒體技術概論