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!
===Constructor functions=== Another option, which is rarely used in modern languages, is to use a function to construct a string, rather than representing it via a literal. This is generally not used in modern languages because the computation is done at run time, rather than at parse time. For example, early forms of [[BASIC]] did not include escape sequences or any other workarounds listed here, and thus one instead was required to use the <code>CHR$</code> function, which returns a string containing the character corresponding to its argument. In [[ASCII]] the quotation mark has the value 34, so to represent a string with quotes on an ASCII system one would write <syntaxhighlight lang="qbasic"> "I said, " + CHR$(34) + "Can you hear me?" + CHR$(34) </syntaxhighlight> In C, a similar facility is available via <code>[[sprintf]]</code> and the <code>%c</code> "character" format specifier, though in the presence of other workarounds this is generally not used: <syntaxhighlight lang="c"> char buffer[32]; snprintf(buffer, sizeof buffer, "This is %cin quotes.%c", 34, 34); </syntaxhighlight> These constructor functions can also be used to represent nonprinting characters, though escape sequences are generally used instead. A similar technique can be used in C++ with the <code>std::string</code> stringification operator.
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)