Literals/String: Difference between revisions
Content deleted Content added
→{{header|Swift}}: Added Swift multi-line string literals |
m Moved Wren entry into correct alphabetical order. |
||
Line 2,736:
Pool strings consisting of exactly one character represent numbers 0-255 according to their ASCII character code.
=={{header|Wren}}==
In Wren a string is an immutable array of bytes. They are usually interpreted as UTF-8 but don't have to be and invalid UTF-8 sequences are permitted. A string can also include the zero byte (\0) which is not interpreted as a string terminator as would be the case in C.
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 literals must be surrounded in double quotes and support the following escape characters:
{| class="wikitable"
! Character !! Meaning
|-
| \0 || The NUL byte: 0
|-
| \" || A double quote character
|-
| \\ || A backslash
|-
| \% || A percent sign (see below)
|-
| \a || Alarm beep
|-
| \b || Backspace
|-
| \f || Form feed
|-
| \n || Newline
|-
| \r || Carriage return
|-
| \t || Tab
|-
| \v || Vertical tab
|-
| \xhh || A single byte with hex value '0xhh'
|-
| \uhhhh || A Unicode code point within the basic multilingual plane
|-
| \Uhhhhhhhh || Any Unicode code point including emojis
|}
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 \%.
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)"
System.print([s, t, u, v])</lang>
{{out}}
<pre>
[abc123, abc 123%, 🙊🚀, abcabcabc]
</pre>
=={{header|Xojo}}==
Line 2,799 ⟶ 2,851:
Double and single quote characters may also be escaped with XML entities: &quot; and &apos; respectively.
=={{header|zkl}}==
|