Quoting constructs: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Ring}}: missing the point of the task) |
(→{{header|Lua}}: added Lua solution) |
||
Line 323: | Line 323: | ||
5 |
5 |
||
</lang> |
</lang> |
||
=={{header|Lua}}== |
|||
Lua has three string definition syntaxes: single- and double-quotes, which are equivalent; and long-bracket pairs [[ ]] which may span multiple lines. Long-bracket pairs may be specified to an arbitrary depth, which may be useful for quoting Lua source code itself (which might use long-brackets). Lua strings are variable-length arrays of bytes, not 0-terminated (as in C), so may contain aribitrary raw binary data. Commonly escaped characters and octal\hexadecimal notation are supported. |
|||
<lang lua>s1 = "This is a double-quoted 'string' with embedded single-quotes." |
|||
s2 = 'This is a single-quoted "string" with embedded double-quotes.' |
|||
s3 = "this is a double-quoted \"string\" with escaped double-quotes." |
|||
s4 = 'this is a single-quoted \'string\' with escaped single-quotes.' |
|||
s5 = [[This is a long-bracket "'string'" with embedded single- and double-quotes.]] |
|||
s6 = [=[This is a level 1 long-bracket ]]string[[ with [[embedded]] long-brackets.]=] |
|||
s7 = [==[This is a level 2 long-bracket ]=]string[=[ with [=[embedded]=] level 1 long-brackets, etc.]==] |
|||
s8 = [[This is |
|||
a long-bracket string |
|||
with embedded |
|||
line feeds]] |
|||
s9 = "any \0 form \1 of \2 string \3 may \4 contain \5 raw \6 binary \7 data \xDB" |
|||
print(s1) |
|||
print(s2) |
|||
print(s3) |
|||
print(s4) |
|||
print(s5) |
|||
print(s6) |
|||
print(s7) |
|||
print(s8) |
|||
print(s9) -- with audible "bell" from \7 if supported by os |
|||
print("some raw binary:", #s9, s9:byte(5), s9:byte(12), s9:byte(17))</lang> |
|||
{{out}} |
|||
<pre>This is a double-quoted 'string' with embedded single-quotes. |
|||
This is a single-quoted "string" with embedded double-quotes. |
|||
this is a double-quoted "string" with escaped double-quotes. |
|||
this is a single-quoted 'string' with escaped single-quotes. |
|||
This is a long-bracket "'string'" with embedded single- and double-quotes. |
|||
This is a level 1 long-bracket ]]string[[ with [[embedded]] long-brackets. |
|||
This is a level 2 long-bracket ]=]string[=[ with [=[embedded]=] level 1 long-brackets, etc. |
|||
This is |
|||
a long-bracket string |
|||
with embedded |
|||
line feeds |
|||
any form ☺ of ☻ string ♥ may ♦ contain ♣ raw ♠ binary █ data |
|||
some raw binary: 65 0 1 2</pre> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |