Literals/String: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) Rename Perl 6 -> Raku, alphabetize, minor clean-up |
Added Wren |
||
Line 2,636: | Line 2,636: | ||
Double and single quote characters may also be escaped with XML entities: " and ' respectively. |
Double and single quote characters may also be escaped with XML entities: " and ' respectively. |
||
=={{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 is 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|zkl}}== |
=={{header|zkl}}== |