Literals/String: Difference between revisions

→‎{{header|Wren}}: Updated to v0.4.0.
m (→‎{{header|LaTeX}}: Fixed extra quotation marks and shortened.)
(→‎{{header|Wren}}: Updated to v0.4.0.)
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).
 
String''Ordinary'' string literals must be surrounded in double quotes and support the following escape characters:
{| class="wikitable"
! Character !! Meaning
Line 2,911:
|-
| \b || Backspace
|-
| \e || ESC character
|-
| \f || Form feed
Line 2,929 ⟶ 2,931:
|}
 
String''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"
var t = "abc\t123\%"
var u = "\U0001F64A\U0001F680"
var v = "%("abc" * 3)"
var w = """a"bc""def\n%(v)"""
System.print([s, t, u, v])</lang>
 
System.print([s, t, u, v, w])</lang>
 
{{out}}
<pre>
[abc123, abc 123%, 🙊🚀, abcabcabc, a"bc""def\n%(v)]
</pre>
 
9,476

edits