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!
===Delimiter quoting=== [[C++11]] introduced so-called ''raw string literals''. They consist, essentially of :<code>R" ''end-of-string-id'' ( ''content'' ) ''end-of-string-id'' "</code>, that is, after <code>R"</code> the programmer can enter up to 16 characters except whitespace characters, parentheses, or backslash, which form the ''end-of-string-id'' (its purpose is to be repeated to signal the end of the string, ''eos id'' for short), then an opening parenthesis (to denote the end of the eos id) is required. Then follows the actual content of the literal: Any sequence characters may be used (except that it may not contain a closing parenthesis followed by the eos id followed a quote), and finally β to terminate the string β a closing parenthesis, the eos id, and a quote is required.<br/> The simplest case of such a literal is with empty content and empty eos id: <code>R"()"</code>.<br/> The eos id may itself contain quotes: {{code|2=cpp|1=R""(I asked, "Can you hear me?")""}} is a valid literal (the eos id is <code>"</code> here.)<br/> Escape sequences don't work in raw string literals. [[D (programming language)|D]] supports a few quoting delimiters, with such strings starting with <code>q"</code> plus an opening delimiter and ending with the respective closing delimiter and <code>"</code>. Available delimiter pairs are <code>()</code>, <code><></code>, <code>{}</code>, and <code>[]</code>; an unpaired non-identifier delimiter is its own closing delimiter. The paired delimiters nest, so that {{code|2=d|1=q"(A pair "()" of parens in quotes)"}} is a valid literal; an example with the non-nesting <code>/</code> character is {{code|2=d|1=q"/I asked, "Can you hear me?"/"}}.<br/> Similar to C++11, D allows here-document-style literals with end-of-string ids: :<code>q" ''end-of-string-id'' newline ''content'' newline ''end-of-string-id'' "</code> In D, the ''end-of-string-id'' must be an identifier (alphanumeric characters). In some programming languages, such as [[Bourne shell|sh]] and [[Perl]], there are different delimiters that are treated differently, such as doing string interpolation or not, and thus care must be taken when choosing which delimiter to use; see [[#Different kinds of strings|different kinds of strings]], below.
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)