- 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"
- 現(xiàn)代C++編程:從入門到實踐
- C及C++程序設(shè)計(第4版)
- 碼上行動:零基礎(chǔ)學會Python編程(ChatGPT版)
- C語言程序設(shè)計實訓教程
- 網(wǎng)頁設(shè)計與制作教程(HTML+CSS+JavaScript)(第2版)
- 網(wǎng)店設(shè)計看這本就夠了
- Spring Boot企業(yè)級項目開發(fā)實戰(zhàn)
- Working with Odoo
- 程序設(shè)計基礎(chǔ)教程:C語言
- ASP.NET Core 2 Fundamentals
- ExtJS高級程序設(shè)計
- 智能手機APP UI設(shè)計與應(yīng)用任務(wù)教程
- Buildbox 2.x Game Development
- Mastering Concurrency Programming with Java 9(Second Edition)
- App Inventor 2 Essentials