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

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:

主站蜘蛛池模板: 嘉兴市| 德庆县| 五指山市| 临夏县| 大田县| 托克托县| 桦甸市| 繁峙县| 内江市| 苏尼特左旗| 晋江市| 禄丰县| 金溪县| 威宁| 来凤县| 沅陵县| 隆尧县| 格尔木市| 四子王旗| 佛山市| 左权县| 象州县| 五家渠市| 樟树市| 西宁市| 永康市| 巴东县| 长宁县| 青海省| 双牌县| 新干县| 陆河县| 六盘水市| 云南省| 开封市| 阳曲县| 卢湾区| 沛县| 肥乡县| 葵青区| 昌邑市|