Kotlin String templates support (#22150)

pull/34391/head^2
Samuel Koprivnjak 2018-11-18 17:21:46 +01:00 committed by nik
parent ab6a0f4613
commit 337eae598b
1 changed files with 15 additions and 1 deletions

View File

@ -44,6 +44,20 @@ abc1def
Even without explicitly converting `Int` value 1 to `String` object first, the resulting output is still a `String`.
Kotlin also supports String templates (expression that starts with dollar sign $) which are preferred to string concatenation.
```kotlin
var a = 1
// simple name in template:
val s1 = "a is $a"
```
```kotlin
a = 2
// arbitrary expression in template:
val s2 = "${s1.replace("is", "was")}, but now is $a"
```
#### String with Multiple Lines
Programmers can declare `String` variables with multiple lines by using triple quotes instead of double quotes
@ -251,4 +265,4 @@ Output:
#### Resources
* [Kotlin Basic Types](https://kotlinlang.org/docs/reference/basic-types.html)
* [Kotlin String Reference](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)
* [Kotlin String Reference](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)