- 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:
推薦閱讀
- 國際大學生程序設(shè)計競賽中山大學內(nèi)部選拔真題解(二)
- Mobile Application Development:JavaScript Frameworks
- Objective-C Memory Management Essentials
- SQL語言從入門到精通
- Mastering Ubuntu Server
- 深入淺出Serverless:技術(shù)原理與應(yīng)用實踐
- Learning Laravel's Eloquent
- 0 bug:C/C++商用工程之道
- 速學Python:程序設(shè)計從入門到進階
- Hands-On Neural Network Programming with C#
- Unity 2017 Game AI Programming(Third Edition)
- Backbone.js Testing
- Mobile Forensics:Advanced Investigative Strategies
- C++17 By Example
- Android應(yīng)用程序設(shè)計