Literals/String: Difference between revisions
Content added Content deleted
m (→{{header|LaTeX}}: Fixed extra quotation marks and shortened.) |
(→{{header|Wren}}: Updated to v0.4.0.) |
||
Line 2,896: | Line 2,896: | ||
All strings are instances of the built-in String class and there is no separate Character class as such. Characters are simply strings consisting of a single byte or Unicode code point (1 to 4 bytes). |
All strings are instances of the built-in String class and there is no separate Character class as such. Characters are simply strings consisting of a single byte or Unicode code point (1 to 4 bytes). |
||
''Ordinary'' string literals must be surrounded in double quotes and support the following escape characters: |
|||
{| class="wikitable" |
{| class="wikitable" |
||
! Character !! Meaning |
! Character !! Meaning |
||
Line 2,911: | Line 2,911: | ||
|- |
|- |
||
| \b || Backspace |
| \b || Backspace |
||
|- |
|||
| \e || ESC character |
|||
|- |
|- |
||
| \f || Form feed |
| \f || Form feed |
||
Line 2,929: | Line 2,931: | ||
|} |
|} |
||
''Ordinary'' string literals also allow interpolation. If you have a percent sign (%) followed by a parenthesized expression, the expression is evaluated and can be arbitrarily complex. Consequently, if you need to include a normal % character in a string literal, you have to use the escaped form \%. |
|||
From v0.4.0 Wren also supports ''raw'' string literals. These are any text surrounded by triple double quotes, """, and are interpreted verbatim i.e. any control codes and/or interpolations are not processed as such. They can include single or double double quotes without problem. |
|||
Wren doesn't support verbatim strings or here documents. |
|||
<lang ecmascript>var s = "abc123" |
<lang ecmascript>var s = "abc123" |
||
var t = "abc\t123\%" |
var t = "abc\t123\%" |
||
var u = "\U0001F64A\U0001F680" |
var u = "\U0001F64A\U0001F680" |
||
var v = "%("abc" * 3)" |
var v = "%("abc" * 3)" |
||
var w = """a"bc""def\n%(v)""" |
|||
⚫ | |||
⚫ | |||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
[abc123, abc 123%, 🙊🚀, abcabcabc] |
[abc123, abc 123%, 🙊🚀, abcabcabc, a"bc""def\n%(v)] |
||
</pre> |
</pre> |
||