Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
String literal
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Multiple quoting=== A further extension is the use of ''multiple quoting'', which allows the author to choose which characters should specify the bounds of a string literal. For example, in [[Perl]]: <syntaxhighlight lang="perl"> qq^I said, "Can you hear me?"^ qq@I said, "Can you hear me?"@ qq§I said, "Can you hear me?"§ </syntaxhighlight> all produce the desired result. Although this notation is more flexible, few languages support it; other than Perl, [[Ruby (programming language)|Ruby]] (influenced by Perl) and [[C++11]] also support these. A variant of multiple quoting is the use of [[here document]]-style strings. Lua (as of 5.1) provides a limited form of multiple quoting, particularly to allow nesting of long comments or embedded strings. Normally one uses <code>[[</code> and <code>]]</code> to delimit literal strings (initial newline stripped, otherwise raw), but the opening brackets can include any number of equal signs, and only closing brackets with the same number of signs close the string. For example: <syntaxhighlight lang="lua"> local ls = [=[ This notation can be used for Windows paths: local path = [[C:\Windows\Fonts]] ]=] </syntaxhighlight> Multiple quoting is particularly useful with [[regular expression]]s that contain usual delimiters such as quotes, as this avoids needing to escape them. An early example is [[sed]], where in the substitution command <code>s/'''regex'''/'''replacement'''/</code> the default slash <code>/</code> delimiters can be replaced by another character, as in <code>s,'''regex''','''replacement''',</code> .
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)