官术网_书友最值得收藏!

Multi-line String Literals

We can also define multiline string literals without having to use + + for concatenation. Let's create a multiline string in the example 4b_MultilineString.kts:

val name = "Atrium"
val message = """This is an example of
multiline String $name
"""
println(message)

The output is as follows:

Observe the indentation in the preceding example. If we don't want to use indentation, we can put | and use the trimMargin() function to trim the margin as follows:

val name = "Atrium"
val message = """This is an example of
|multiline String $name
"""
println(message.trimMargin())

The output is as follows:

One more thing that we can do is customize the character that we are going to use for margin separation and pass it to the trimMargin() function as follows:

val name = "Atrium"
val message = """This is an example of
^multiline String $name
"""
println(message.trimMargin("^"))

This gives the following output:

主站蜘蛛池模板: 金溪县| 民县| 通渭县| 内江市| 浙江省| 田阳县| 阿拉尔市| 鹤峰县| 福泉市| 凤山市| 岢岚县| 全椒县| 新干县| 昔阳县| 兴国县| 桂东县| 荆门市| 红原县| 东港市| 桐庐县| 邯郸县| 英吉沙县| 裕民县| 阳东县| 宁化县| 阳泉市| 桓仁| 津市市| 察隅县| 兴宁市| 泰来县| 历史| 河池市| 长治县| 翁源县| 乌鲁木齐县| 基隆市| 仪陇县| 休宁县| 防城港市| 外汇|