- Kotlin for Enterprise Applications using Java EE
- Raghavendra Rao K
- 155字
- 2021-06-10 18:49:19
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:
推薦閱讀
- ExtGWT Rich Internet Application Cookbook
- Python for Secret Agents:Volume II
- C# Programming Cookbook
- Arduino開發實戰指南:LabVIEW卷
- C語言程序設計案例式教程
- Easy Web Development with WaveMaker
- 可解釋機器學習:模型、方法與實踐
- NGINX Cookbook
- 詳解MATLAB圖形繪制技術
- Android驅動開發權威指南
- ASP.NET程序開發范例寶典
- 細說Python編程:從入門到科學計算
- DB2SQL性能調優秘笈
- Implementing Microsoft Dynamics NAV(Third Edition)
- Visual FoxPro程序設計習題及實驗指導