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

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:

主站蜘蛛池模板: 高州市| 临漳县| 呼伦贝尔市| 鄯善县| 荔波县| 鞍山市| 蓬安县| 满城县| 驻马店市| 维西| 南京市| 定陶县| 安宁市| 航空| 敖汉旗| 蓬莱市| 远安县| 武平县| 南阳市| 余江县| 当涂县| 买车| 化州市| 新余市| 黄骅市| 西昌市| 新丰县| 宁德市| 鸡泽县| 井冈山市| 扎鲁特旗| 南充市| 交口县| 大姚县| 绥宁县| 宾川县| 法库县| 荣成市| 广宗县| 齐齐哈尔市| 东乡族自治县|