Literals/String: Difference between revisions
Content deleted Content added
Added Kotlin |
|||
Line 983: | Line 983: | ||
jq allows the shorthand: "The value of s is \(s)", and in general, arbitrarily many such interpolations may be made. |
jq allows the shorthand: "The value of s is \(s)", and in general, arbitrarily many such interpolations may be made. |
||
=={{header|Kotlin}}== |
|||
Kotlin supports two kinds of string literals (UTF-16 encoded): |
|||
* escaped string literals, enclosed in double-quotes, which can contain 'escaped characters'. |
|||
* raw string literals, enclosed in triple double-quotes, which ignore escaping but can contain new lines. |
|||
The language also supports character literals - a single UTF-16 character (including an escaped character) enclosed in single quotes. |
|||
Here are some examples of these : |
|||
<lang scala>// version 1.0.6 |
|||
fun main(args: Array<String>) { |
|||
val cl = 'a' // character literal - can contain escaped character |
|||
val esl = "abc\ndef" // escaped string literal - can contain escaped character(s) |
|||
val rsl = """ |
|||
This is a raw string literal |
|||
which does not treat escaped characters |
|||
(\t, \b, \n, \r, \', \", \\, \$ and \u) |
|||
specially and can contain new lines. |
|||
"Quotes" or doubled ""quotes"" can |
|||
be included without problem but not |
|||
tripled quotes. |
|||
""" |
|||
val msl = """ |
|||
|Leading whitepace can be removed from a raw |
|||
|string literal by including |
|||
|a margin prefix ('|' is the default) |
|||
|in combination with the trimMargin function. |
|||
""". trimMargin() |
|||
println(cl) |
|||
println(esl) |
|||
println(rsl) |
|||
println(msl) |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
a |
|||
abc |
|||
def |
|||
This is a raw string literal |
|||
which does not treat escaped characters |
|||
(\t, \b, \n, \r, \', \", \\, \$ and \u) |
|||
specially and can contain new lines. |
|||
"Quotes" or doubled ""quotes"" can |
|||
be included without problem but not |
|||
tripled quotes. |
|||
Leading whitepace can be removed from a raw |
|||
string literal by including |
|||
a margin ('|' is the default) |
|||
in combination with the trimMargin function. |
|||
</pre> |
|||
=={{header|Lasso}}== |
=={{header|Lasso}}== |