<s>
A	O
string	B-Language
literal	I-Language
or	O
anonymous	O
string	O
is	O
a	O
literal	O
for	O
a	O
string	O
value	O
in	O
the	O
source	O
code	O
of	O
a	O
computer	B-Application
program	I-Application
.	O
</s>
<s>
Modern	O
programming	B-General_Concept
languages	O
commonly	O
use	O
a	O
quoted	O
sequence	O
of	O
characters	O
,	O
formally	O
"	O
bracketed	O
delimiters	B-Algorithm
"	O
,	O
as	O
in	O
x	O
=	O
"	O
foo	O
"	O
,	O
where	O
"	O
foo	O
"	O
is	O
a	O
string	B-Language
literal	I-Language
with	O
value	O
foo	O
.	O
</s>
<s>
Methods	O
such	O
as	O
escape	O
sequences	O
can	O
be	O
used	O
to	O
avoid	O
the	O
problem	O
of	O
delimiter	B-Algorithm
collision	O
(	O
issues	O
with	O
brackets	O
)	O
and	O
allow	O
the	O
delimiters	B-Algorithm
to	O
be	O
embedded	O
in	O
a	O
string	O
.	O
</s>
<s>
There	O
are	O
many	O
alternate	O
notations	O
for	O
specifying	O
string	B-Language
literals	I-Language
especially	O
in	O
complicated	O
cases	O
.	O
</s>
<s>
The	O
exact	O
notation	O
depends	O
on	O
the	O
programming	B-General_Concept
language	O
in	O
question	O
.	O
</s>
<s>
Nevertheless	O
,	O
there	O
are	O
general	O
guidelines	O
that	O
most	O
modern	O
programming	B-General_Concept
languages	O
follow	O
.	O
</s>
<s>
to	O
specify	O
string	B-Language
literals	I-Language
.	O
</s>
<s>
Double	O
quotations	O
are	O
the	O
most	O
common	O
quoting	B-Language
delimiters	B-Algorithm
used	O
:	O
</s>
<s>
In	O
terms	O
of	O
regular	B-Language
expressions	I-Language
,	O
a	O
basic	O
quoted	O
string	B-Language
literal	I-Language
is	O
given	O
as	O
:	O
</s>
<s>
This	O
means	O
that	O
a	O
string	B-Language
literal	I-Language
is	O
written	O
as	O
:	O
a	O
quote	O
,	O
followed	O
by	O
zero	O
,	O
one	O
,	O
or	O
more	O
non-quote	O
characters	O
,	O
followed	O
by	O
a	O
quote	O
.	O
</s>
<s>
In	O
practice	O
this	O
is	O
often	O
complicated	O
by	O
escaping	O
,	O
other	O
delimiters	B-Algorithm
,	O
and	O
excluding	O
newlines	O
.	O
</s>
<s>
A	O
number	O
of	O
languages	O
provide	O
for	O
paired	O
delimiters	B-Algorithm
,	O
where	O
the	O
opening	O
and	O
closing	O
delimiters	B-Algorithm
are	O
different	O
.	O
</s>
<s>
These	O
also	O
often	O
allow	O
nested	O
strings	O
,	O
so	O
delimiters	B-Algorithm
can	O
be	O
embedded	O
,	O
so	O
long	O
as	O
they	O
are	O
paired	O
,	O
but	O
still	O
result	O
in	O
delimiter	B-Algorithm
collision	O
for	O
embedding	O
an	O
unpaired	O
closing	O
delimiter	B-Algorithm
.	O
</s>
<s>
Examples	O
include	O
PostScript	B-Language
,	O
which	O
uses	O
parentheses	O
,	O
as	O
in	O
(	O
The	O
quick	O
(	O
brown	O
fox	O
)	O
)	O
and	O
m4	B-Device
,	O
which	O
uses	O
the	O
backtick	O
( `	O
)	O
as	O
the	O
starting	O
delimiter	B-Algorithm
,	O
and	O
the	O
apostrophe	B-Language
( 	O
 '	O
)	O
as	O
the	O
ending	O
delimiter	B-Algorithm
.	O
</s>
<s>
Tcl	B-Operating_System
allows	O
both	O
quotes	O
(	O
for	O
interpolated	O
strings	O
)	O
and	O
braces	O
(	O
for	O
raw	O
strings	O
)	O
,	O
as	O
in	O
"	O
The	O
quick	O
brown	O
fox	O
"	O
or	O
{	O
The	O
quick	O
{	O
brown	O
fox}}	O
;	O
this	O
derives	O
from	O
the	O
single	O
quotations	O
in	O
Unix	O
shells	O
and	O
the	O
use	O
of	O
braces	O
in	O
C	B-Language
for	O
compound	O
statements	O
,	O
since	O
blocks	O
of	O
code	O
is	O
in	O
Tcl	B-Operating_System
syntactically	O
the	O
same	O
thing	O
as	O
string	B-Language
literals	I-Language
–	O
that	O
the	O
delimiters	B-Algorithm
are	O
paired	O
is	O
essential	O
for	O
making	O
this	O
feasible	O
.	O
</s>
<s>
These	O
,	O
however	O
,	O
are	O
rarely	O
used	O
,	O
as	O
many	O
programming	B-General_Concept
languages	O
will	O
not	O
register	O
them	O
(	O
one	O
exception	O
is	O
the	O
paired	O
double	O
quotations	O
which	O
can	O
be	O
used	O
in	O
Visual	B-Language
Basic	I-Language
.NET	I-Language
)	O
.	O
</s>
<s>
String	B-Language
literals	I-Language
might	O
be	O
ended	O
by	O
newlines	O
.	O
</s>
<s>
One	O
example	O
is	O
MediaWiki	B-Application
template	O
parameters	O
.	O
</s>
<s>
Some	O
programming	B-General_Concept
languages	O
,	O
such	O
as	O
Perl	B-Language
and	O
PHP	B-Application
,	O
allow	O
string	B-Language
literals	I-Language
without	O
any	O
delimiters	B-Algorithm
in	O
some	O
contexts	O
.	O
</s>
<s>
In	O
the	O
following	O
Perl	B-Language
program	O
,	O
for	O
example	O
,	O
red	O
,	O
green	O
,	O
and	O
blue	O
are	O
string	B-Language
literals	I-Language
,	O
but	O
are	O
unquoted	O
:	O
</s>
<s>
Perl	B-Language
treats	O
non-reserved	O
sequences	O
of	O
alphanumeric	O
characters	O
as	O
string	B-Language
literals	I-Language
in	O
most	O
contexts	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
following	O
two	O
lines	O
of	O
Perl	B-Language
are	O
equivalent	O
:	O
</s>
<s>
In	O
the	O
original	O
FORTRAN	B-Application
programming	I-Application
language	I-Application
(	O
for	O
example	O
)	O
,	O
string	B-Language
literals	I-Language
were	O
written	O
in	O
so-called	O
Hollerith	O
notation	O
,	O
where	O
a	O
decimal	O
count	O
of	O
the	O
number	O
of	O
characters	O
was	O
followed	O
by	O
the	O
letter	O
H	O
,	O
and	O
then	O
the	O
characters	O
of	O
the	O
string	O
:	O
</s>
<s>
C++	O
has	O
two	O
styles	O
of	O
string	O
,	O
one	O
inherited	O
from	O
C	B-Language
(	O
delimited	B-Algorithm
by	O
"	O
)	O
,	O
and	O
the	O
safer	O
std::string	O
in	O
the	O
C++	O
Standard	O
Library	O
.	O
</s>
<s>
The	O
std::string	O
class	O
is	O
frequently	O
used	O
in	O
the	O
same	O
way	O
a	O
string	B-Language
literal	I-Language
would	O
be	O
used	O
in	O
other	O
languages	O
,	O
and	O
is	O
often	O
preferred	O
to	O
C-style	O
strings	O
for	O
its	O
greater	O
flexibility	O
and	O
safety	O
.	O
</s>
<s>
But	O
it	O
comes	O
with	O
a	O
performance	O
penalty	O
for	O
string	B-Language
literals	I-Language
,	O
as	O
std::string	O
usually	O
allocates	O
memory	O
dynamically	O
,	O
and	O
must	O
copy	O
the	O
C-style	O
string	B-Language
literal	I-Language
to	O
it	O
at	O
run	O
time	O
.	O
</s>
<s>
Before	O
C++11	B-Language
,	O
there	O
was	O
no	O
literal	O
for	O
C++	O
strings	O
(	O
C++11	B-Language
allows	O
"	O
this	O
is	O
a	O
C++	O
string	O
"	O
s	O
with	O
the	O
s	O
at	O
the	O
end	O
of	O
the	O
literal	O
)	O
,	O
so	O
the	O
normal	O
constructor	O
syntax	O
was	O
used	O
,	O
for	O
example	O
:	O
</s>
<s>
Since	O
C++11	B-Language
,	O
there	O
is	O
also	O
new	O
constructor	O
syntax	O
:	O
</s>
<s>
When	O
using	O
quoting	B-Language
,	O
if	O
one	O
wishes	O
to	O
represent	O
the	O
delimiter	B-Algorithm
itself	O
in	O
a	O
string	B-Language
literal	I-Language
,	O
one	O
runs	O
into	O
the	O
problem	O
of	O
delimiter	B-Algorithm
collision	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
the	O
delimiter	B-Algorithm
is	O
a	O
double	O
quote	O
,	O
one	O
cannot	O
simply	O
represent	O
a	O
double	O
quote	O
itself	O
by	O
the	O
literal	O
"""	O
as	O
the	O
second	O
quote	O
is	O
interpreted	O
as	O
the	O
end	O
of	O
the	O
string	B-Language
literal	I-Language
,	O
not	O
as	O
the	O
value	O
of	O
the	O
string	O
,	O
and	O
similarly	O
one	O
cannot	O
write	O
"	O
This	O
is	O
"	O
in	O
quotes	O
"	O
,	O
but	O
invalid.	O
"	O
</s>
<s>
</s>
<s>
Some	O
languages	O
,	O
such	O
as	O
Fortran	B-Application
,	O
Modula-2	B-Language
,	O
JavaScript	B-Language
,	O
Python	B-Language
,	O
and	O
PHP	B-Application
allow	O
more	O
than	O
one	O
quoting	B-Language
delimiter	B-Algorithm
;	O
in	O
the	O
case	O
of	O
two	O
possible	O
delimiters	B-Algorithm
,	O
this	O
is	O
known	O
as	O
dual	O
quoting	B-Language
.	O
</s>
<s>
Typically	O
,	O
this	O
consists	O
of	O
allowing	O
the	O
programmer	B-Application
to	O
use	O
either	O
single	O
quotations	O
or	O
double	O
quotations	O
interchangeably	O
–	O
each	O
literal	O
must	O
use	O
one	O
or	O
the	O
other	O
.	O
</s>
<s>
This	O
does	O
not	O
allow	O
having	O
a	O
single	O
literal	O
with	O
both	O
delimiters	B-Algorithm
in	O
it	O
,	O
however	O
.	O
</s>
<s>
Python	B-Language
has	O
string	B-Language
literal	I-Language
concatenation	O
,	O
so	O
consecutive	O
string	B-Language
literals	I-Language
are	O
concatenated	O
even	O
without	O
an	O
operator	O
,	O
so	O
this	O
can	O
be	O
reduced	O
to	O
:	O
</s>
<s>
D	B-Application
supports	O
a	O
few	O
quoting	B-Language
delimiters	B-Algorithm
,	O
with	O
such	O
strings	O
starting	O
with	O
q	O
"	O
[	O
and	O
ending	O
with	O
]	O
"	O
or	O
similarly	O
for	O
other	O
delimiter	B-Algorithm
character	O
(	O
any	O
of	O
(	O
)	O
<>	O
 {  } 	O
or	O
 [  ] 	O
)	O
.	O
</s>
<s>
D	B-Application
also	O
supports	O
here	O
document-style	O
strings	O
via	O
similar	O
syntax	O
.	O
</s>
<s>
In	O
some	O
programming	B-General_Concept
languages	O
,	O
such	O
as	O
sh	B-Device
and	O
Perl	B-Language
,	O
there	O
are	O
different	O
delimiters	B-Algorithm
that	O
are	O
treated	O
differently	O
,	O
such	O
as	O
doing	O
string	O
interpolation	O
or	O
not	O
,	O
and	O
thus	O
care	O
must	O
be	O
taken	O
when	O
choosing	O
which	O
delimiter	B-Algorithm
to	O
use	O
;	O
see	O
different	O
kinds	O
of	O
strings	O
,	O
below	O
.	O
</s>
<s>
A	O
further	O
extension	O
is	O
the	O
use	O
of	O
multiple	O
quoting	B-Language
,	O
which	O
allows	O
the	O
author	O
to	O
choose	O
which	O
characters	O
should	O
specify	O
the	O
bounds	O
of	O
a	O
string	B-Language
literal	I-Language
.	O
</s>
<s>
For	O
example	O
,	O
in	O
Perl	B-Language
:	O
</s>
<s>
Although	O
this	O
notation	O
is	O
more	O
flexible	O
,	O
few	O
languages	O
support	O
it	O
;	O
other	O
than	O
Perl	B-Language
,	O
Ruby	B-Language
(	O
influenced	O
by	O
Perl	B-Language
)	O
and	O
C++11	B-Language
also	O
support	O
these	O
.	O
</s>
<s>
In	O
C++11	B-Language
,	O
raw	O
strings	O
can	O
have	O
various	O
delimiters	B-Algorithm
,	O
beginning	O
with	O
R	O
"	O
delimiter( and end with )	O
delimiter	B-Algorithm
"	O
.	O
</s>
<s>
The	O
delimiter	B-Algorithm
can	O
be	O
from	O
zero	O
to	O
16	O
characters	O
long	O
and	O
may	O
contain	O
any	O
member	O
of	O
the	O
basic	O
source	O
character	O
set	O
except	O
whitespace	O
characters	O
,	O
parentheses	O
,	O
or	O
backslash	O
.	O
</s>
<s>
A	O
variant	O
of	O
multiple	O
quoting	B-Language
is	O
the	O
use	O
of	O
here	O
document-style	O
strings	O
.	O
</s>
<s>
Lua	O
(	O
as	O
of	O
5.1	O
)	O
provides	O
a	O
limited	O
form	O
of	O
multiple	O
quoting	B-Language
,	O
particularly	O
to	O
allow	O
nesting	O
of	O
long	O
comments	O
or	O
embedded	O
strings	O
.	O
</s>
<s>
Normally	O
one	O
uses	O
[ [ 	O
and	O
 ] ]	O
to	O
delimit	B-Algorithm
literal	B-Language
strings	I-Language
(	O
initial	O
newline	O
stripped	O
,	O
otherwise	O
raw	O
)	O
,	O
but	O
the	O
opening	O
brackets	O
can	O
include	O
any	O
number	O
of	O
equal	O
signs	O
,	O
and	O
only	O
closing	O
brackets	O
with	O
the	O
same	O
number	O
of	O
signs	O
close	O
the	O
string	O
.	O
</s>
<s>
Multiple	O
quoting	B-Language
is	O
particularly	O
useful	O
with	O
regular	B-Language
expressions	I-Language
that	O
contain	O
usual	O
delimiters	B-Algorithm
such	O
as	O
quotes	O
,	O
as	O
this	O
avoids	O
needing	O
to	O
escape	O
them	O
.	O
</s>
<s>
An	O
early	O
example	O
is	O
sed	B-Application
,	O
where	O
in	O
the	O
substitution	O
command	O
s/regex/replacement/	O
the	O
default	O
slash	O
/	O
delimiters	B-Algorithm
can	O
be	O
replaced	O
by	O
another	O
character	O
,	O
as	O
in	O
s	O
,	O
regex	B-Language
,	O
replacement	O
,	O
.	O
</s>
<s>
In	O
C	B-Language
,	O
a	O
similar	O
facility	O
is	O
available	O
via	O
sprintf	O
and	O
the	O
%c	O
"	O
character	O
"	O
format	O
specifier	O
,	O
though	O
in	O
the	O
presence	O
of	O
other	O
workarounds	O
this	O
is	O
generally	O
not	O
used	O
:	O
</s>
<s>
A	O
similar	O
technique	O
can	O
be	O
used	O
in	O
C++	O
with	O
the	O
std::string	O
stringification	O
operator	O
.	O
</s>
<s>
Escape	O
sequences	O
are	O
a	O
general	O
technique	O
for	O
representing	O
characters	O
that	O
are	O
otherwise	O
difficult	O
to	O
represent	O
directly	O
,	O
including	O
delimiters	B-Algorithm
,	O
nonprinting	O
characters	O
(	O
such	O
as	O
backspaces	O
)	O
,	O
newlines	O
,	O
and	O
whitespace	O
characters	O
(	O
which	O
are	O
otherwise	O
impossible	O
to	O
distinguish	O
visually	O
)	O
,	O
and	O
have	O
a	O
long	O
history	O
.	O
</s>
<s>
They	O
are	O
accordingly	O
widely	O
used	O
in	O
string	B-Language
literals	I-Language
,	O
and	O
adding	O
an	O
escape	O
sequence	O
(	O
either	O
to	O
a	O
single	O
character	O
or	O
throughout	O
a	O
string	O
)	O
is	O
known	O
as	O
escaping	O
.	O
</s>
<s>
Most	O
commonly	O
this	O
is	O
backslash	O
;	O
in	O
addition	O
to	O
other	O
characters	O
,	O
a	O
key	O
point	O
is	O
that	O
backslash	O
itself	O
can	O
be	O
encoded	O
as	O
a	O
double	O
backslash	O
\\	O
and	O
for	O
delimited	B-Algorithm
strings	O
the	O
delimiter	B-Algorithm
itself	O
can	O
be	O
encoded	O
by	O
escaping	O
,	O
say	O
by	O
\	O
 "	O
for	O
"	O
.	O
</s>
<s>
A	O
regular	B-Language
expression	I-Language
for	O
such	O
escaped	O
strings	O
can	O
be	O
given	O
as	O
follows	O
,	O
as	O
found	O
in	O
the	O
ANSI	O
C	B-Language
specification	O
:	O
</s>
<s>
An	O
escaped	O
string	O
must	O
then	O
itself	O
be	O
lexically	B-Application
analyzed	I-Application
,	O
converting	O
the	O
escaped	O
string	O
into	O
the	O
unescaped	O
string	O
that	O
it	O
represents	O
.	O
</s>
<s>
This	O
is	O
done	O
during	O
the	O
evaluation	O
phase	O
of	O
the	O
overall	O
lexing	B-Application
of	O
the	O
computer	O
language	O
:	O
the	O
evaluator	O
of	O
the	O
lexer	B-Application
of	O
the	O
overall	O
language	O
executes	O
its	O
own	O
lexer	B-Application
for	O
escaped	O
string	B-Language
literals	I-Language
.	O
</s>
<s>
Among	O
other	O
things	O
,	O
it	O
must	O
be	O
possible	O
to	O
encode	O
the	O
character	O
that	O
normally	O
terminates	O
the	O
string	O
constant	O
,	O
plus	O
there	O
must	O
be	O
some	O
way	O
to	O
specify	O
the	O
escape	B-Algorithm
character	I-Algorithm
itself	O
.	O
</s>
<s>
Escape	O
sequences	O
,	O
however	O
,	O
solve	O
every	O
delimiter	B-Algorithm
problem	O
and	O
most	O
compilers	O
interpret	O
escape	O
sequences	O
.	O
</s>
<s>
When	O
an	O
escape	B-Algorithm
character	I-Algorithm
is	O
inside	O
a	O
string	B-Language
literal	I-Language
,	O
it	O
means	O
"	O
this	O
is	O
the	O
start	O
of	O
the	O
escape	O
sequence	O
"	O
.	O
</s>
<s>
The	O
escape	B-Algorithm
character	I-Algorithm
is	O
on	O
the	O
top/left	O
of	O
the	O
keyboard	O
,	O
but	O
the	O
editor	O
will	O
translate	O
it	O
,	O
therefore	O
it	O
is	O
not	O
directly	O
tapeable	O
into	O
a	O
string	O
.	O
</s>
<s>
The	O
backslash	O
is	O
used	O
to	O
represent	O
the	O
escape	B-Algorithm
character	I-Algorithm
in	O
a	O
string	B-Language
literal	I-Language
.	O
</s>
<s>
Many	O
languages	O
support	O
the	O
use	O
of	O
metacharacters	B-Algorithm
inside	O
string	B-Language
literals	I-Language
.	O
</s>
<s>
Metacharacters	B-Algorithm
have	O
varying	O
interpretations	O
depending	O
on	O
the	O
context	B-Language
and	O
language	O
,	O
but	O
are	O
generally	O
a	O
kind	O
of	O
'	O
processing	O
command	O
 '	O
for	O
representing	O
printing	O
or	O
nonprinting	O
characters	O
.	O
</s>
<s>
For	O
instance	O
,	O
in	O
a	O
C	B-Language
string	I-Language
literal	O
,	O
if	O
the	O
backslash	O
is	O
followed	O
by	O
a	O
letter	O
such	O
as	O
"	O
b	O
"	O
,	O
"	O
n	O
"	O
or	O
"	O
t	O
"	O
,	O
then	O
this	O
represents	O
a	O
nonprinting	O
backspace	O
,	O
newline	O
or	O
tab	O
character	O
respectively	O
.	O
</s>
<s>
Or	O
if	O
the	O
backslash	O
is	O
followed	O
by	O
1-3	O
octal	O
digits	O
,	O
then	O
this	O
sequence	O
is	O
interpreted	O
as	O
representing	O
the	O
arbitrary	O
character	O
with	O
the	O
specified	O
ASCII	B-Protocol
code	I-Protocol
.	O
</s>
<s>
</s>
<s>
When	O
code	O
in	O
one	O
programming	B-General_Concept
language	O
is	O
embedded	O
inside	O
another	O
,	O
embedded	O
strings	O
may	O
require	O
multiple	O
levels	O
of	O
escaping	O
.	O
</s>
<s>
This	O
is	O
particularly	O
common	O
in	O
regular	B-Language
expressions	I-Language
and	O
SQL	B-Language
query	O
within	O
other	O
languages	O
,	O
or	O
other	O
languages	O
inside	O
shell	O
scripts	O
.	O
</s>
<s>
Incorrect	O
quoting	B-Language
of	O
nested	O
strings	O
can	O
present	O
a	O
security	O
vulnerability	O
.	O
</s>
<s>
Use	O
of	O
untrusted	O
data	O
,	O
as	O
in	O
data	O
fields	O
of	O
an	O
SQL	B-Language
query	O
,	O
should	O
use	O
prepared	B-Language
statements	I-Language
to	O
prevent	O
a	O
code	O
injection	O
attack	O
.	O
</s>
<s>
In	O
PHP	B-Application
2	O
through	O
5.3	O
,	O
there	O
was	O
a	O
feature	O
called	O
magic	B-Language
quotes	I-Language
which	O
automatically	O
escaped	O
strings	O
(	O
for	O
convenience	O
and	O
security	O
)	O
,	O
but	O
due	O
to	O
problems	O
was	O
removed	O
from	O
version	O
5.4	O
onward	O
.	O
</s>
<s>
Raw	O
strings	O
are	O
particularly	O
useful	O
when	O
a	O
common	O
character	O
needs	O
to	O
be	O
escaped	O
,	O
notably	O
in	O
regular	B-Language
expressions	I-Language
(	O
nested	O
as	O
string	B-Language
literals	I-Language
)	O
,	O
where	O
backslash	O
\	O
is	O
widely	O
used	O
,	O
and	O
in	O
DOS/Windows	O
paths	O
,	O
where	O
backslash	O
is	O
used	O
as	O
a	O
path	O
separator	O
.	O
</s>
<s>
The	O
profusion	O
of	O
backslashes	O
is	O
known	O
as	O
leaning	B-Language
toothpick	I-Language
syndrome	I-Language
,	O
and	O
can	O
be	O
reduced	O
by	O
using	O
raw	O
strings	O
.	O
</s>
<s>
Compare	O
escaped	O
and	O
raw	O
pathnames	B-Application
in	O
C#	B-Application
:	O
</s>
<s>
Extreme	O
examples	O
occur	O
when	O
these	O
are	O
combined	O
–	O
Uniform	O
Naming	O
Convention	O
paths	B-Application
begin	O
with	O
\\,	O
and	O
thus	O
an	O
escaped	O
regular	B-Language
expression	I-Language
matching	O
a	O
UNC	O
name	O
begins	O
with	O
8	O
backslashes	O
,	O
"	O
\\\\\\\\",	O
due	O
to	O
needing	O
to	O
escape	O
the	O
string	O
and	O
the	O
regular	B-Language
expression	I-Language
.	O
</s>
<s>
Using	O
raw	O
strings	O
reduces	O
this	O
to	O
4	O
(	O
escaping	O
in	O
the	O
regular	B-Language
expression	I-Language
)	O
,	O
as	O
in	O
C#	B-Application
@	O
"	O
\\\\	O
 "	O
.	O
</s>
<s>
This	O
can	O
be	O
useful	O
when	O
including	O
literal	O
text	O
and	O
scripting	O
code	O
,	O
to	O
keep	O
the	O
document	O
well	B-Language
formed	I-Language
.	O
</s>
<s>
In	O
many	O
languages	O
,	O
string	B-Language
literals	I-Language
can	O
contain	O
literal	O
newlines	O
,	O
spanning	O
several	O
lines	O
.	O
</s>
<s>
Languages	O
that	O
allow	O
literal	O
newlines	O
include	O
bash	O
,	O
Lua	O
,	O
Perl	B-Language
,	O
PHP	B-Application
,	O
R	O
,	O
and	O
Tcl	B-Operating_System
.	O
</s>
<s>
In	O
some	O
other	O
languages	O
string	B-Language
literals	I-Language
cannot	O
include	O
newlines	O
.	O
</s>
<s>
Two	O
issues	O
with	O
multiline	O
string	B-Language
literals	I-Language
are	O
leading	O
and	O
trailing	O
newlines	O
,	O
and	O
indentation	O
.	O
</s>
<s>
If	O
the	O
initial	O
or	O
final	O
delimiters	B-Algorithm
are	O
on	O
separate	O
lines	O
,	O
there	O
are	O
extra	O
newlines	O
,	O
while	O
if	O
they	O
are	O
not	O
,	O
the	O
delimiter	B-Algorithm
makes	O
the	O
string	O
harder	O
to	O
read	O
,	O
particularly	O
for	O
the	O
first	O
line	O
,	O
which	O
is	O
often	O
indented	O
differently	O
from	O
the	O
rest	O
.	O
</s>
<s>
The	O
most	O
common	O
solution	O
for	O
these	O
problems	O
is	O
here	O
document-style	O
string	B-Language
literals	I-Language
.	O
</s>
<s>
Formally	O
speaking	O
,	O
a	O
here	O
document	O
is	O
not	O
a	O
string	B-Language
literal	I-Language
,	O
but	O
instead	O
a	O
stream	O
literal	O
or	O
file	O
literal	O
.	O
</s>
<s>
The	O
opening	O
delimiter	B-Algorithm
is	O
<<	O
END	O
where	O
END	O
can	O
be	O
any	O
word	O
,	O
and	O
the	O
closing	O
delimiter	B-Algorithm
is	O
END	O
on	O
a	O
line	O
by	O
itself	O
,	O
serving	O
as	O
a	O
content	O
boundary	O
–	O
the	O
<<	O
is	O
due	O
to	O
redirecting	O
stdin	O
from	O
the	O
literal	O
.	O
</s>
<s>
Due	O
to	O
the	O
delimiter	B-Algorithm
being	O
arbitrary	O
,	O
these	O
also	O
avoid	O
the	O
problem	O
of	O
delimiter	B-Algorithm
collision	O
.	O
</s>
<s>
The	O
same	O
syntax	O
has	O
since	O
been	O
adopted	O
for	O
multiline	O
string	B-Language
literals	I-Language
in	O
a	O
number	O
of	O
languages	O
,	O
most	O
notably	O
Perl	B-Language
,	O
and	O
are	O
also	O
referred	O
to	O
as	O
here	O
documents	O
,	O
and	O
retain	O
the	O
syntax	O
,	O
despite	O
being	O
strings	O
and	O
not	O
involving	O
redirection	O
.	O
</s>
<s>
As	O
with	O
other	O
string	B-Language
literals	I-Language
,	O
these	O
can	O
sometimes	O
have	O
different	O
behavior	O
specified	O
,	O
such	O
as	O
variable	O
interpolation	O
.	O
</s>
<s>
Python	B-Language
,	O
whose	O
usual	O
string	B-Language
literals	I-Language
do	O
not	O
allow	O
literal	O
newlines	O
,	O
instead	O
has	O
a	O
special	O
form	O
of	O
string	O
,	O
designed	O
for	O
multiline	O
literals	O
,	O
called	O
triple	O
quoting	B-Language
.	O
</s>
<s>
These	O
use	O
a	O
tripled	O
delimiter	B-Algorithm
,	O
either	O
'''	O
or	O
"""	O
.	O
</s>
<s>
These	O
literals	O
are	O
especially	O
used	O
for	O
inline	O
documentation	O
,	O
known	O
as	O
docstrings	B-Language
.	O
</s>
<s>
Tcl	B-Operating_System
allows	O
literal	O
newlines	O
in	O
strings	O
and	O
has	O
no	O
special	O
syntax	O
to	O
assist	O
with	O
multiline	O
strings	O
,	O
though	O
delimiters	B-Algorithm
can	O
be	O
placed	O
on	O
lines	O
by	O
themselves	O
and	O
leading	O
and	O
trailing	O
newlines	O
stripped	O
via	O
string	O
trim	O
,	O
while	O
string	O
map	O
can	O
be	O
used	O
to	O
strip	O
indentation	O
.	O
</s>
<s>
A	O
few	O
languages	O
provide	O
string	B-Language
literal	I-Language
concatenation	O
,	O
where	O
adjacent	O
string	B-Language
literals	I-Language
are	O
implicitly	O
joined	O
into	O
a	O
single	O
literal	O
at	O
compile	O
time	O
.	O
</s>
<s>
This	O
is	O
a	O
feature	O
of	O
C	B-Language
,	O
C++	O
,	O
D	B-Application
,	O
Ruby	B-Language
,	O
and	O
Python	B-Language
,	O
which	O
copied	O
it	O
from	O
C	B-Language
.	O
Notably	O
,	O
this	O
concatenation	O
happens	O
at	O
compile	O
time	O
,	O
during	O
lexical	B-Application
analysis	I-Application
(	O
as	O
a	O
phase	O
following	O
initial	O
tokenization	O
)	O
,	O
and	O
is	O
contrasted	O
with	O
both	O
run	O
time	O
string	O
concatenation	O
(	O
generally	O
with	O
the	O
+	O
operator	O
)	O
and	O
concatenation	O
during	O
constant	O
folding	O
,	O
which	O
occurs	O
at	O
compile	O
time	O
,	O
but	O
in	O
a	O
later	O
phase	O
(	O
after	O
phrase	O
analysis	O
or	O
"	O
parsing	O
"	O
)	O
.	O
</s>
<s>
Most	O
languages	O
,	O
such	O
as	O
C#	B-Application
,	O
Java	O
and	O
Perl	B-Language
,	O
do	O
not	O
support	O
implicit	O
string	B-Language
literal	I-Language
concatenation	O
,	O
and	O
instead	O
require	O
explicit	O
concatenation	O
,	O
such	O
as	O
with	O
the	O
+	O
operator	O
(	O
this	O
is	O
also	O
possible	O
in	O
D	B-Application
and	O
Python	B-Language
,	O
but	O
illegal	O
in	O
C/C	O
++	O
–	O
see	O
below	O
)	O
;	O
in	O
this	O
case	O
concatenation	O
may	O
happen	O
at	O
compile	O
time	O
,	O
via	O
constant	O
folding	O
,	O
or	O
may	O
be	O
deferred	O
to	O
run	O
time	O
.	O
</s>
<s>
In	O
C	B-Language
,	O
where	O
the	O
concept	O
and	O
term	O
originate	O
,	O
string	B-Language
literal	I-Language
concatenation	O
was	O
introduced	O
for	O
two	O
reasons	O
:	O
</s>
<s>
To	O
allow	O
the	O
construction	O
of	O
string	B-Language
literals	I-Language
by	O
macros	O
(	O
via	O
stringizing	O
)	O
.	O
</s>
<s>
In	O
practical	O
terms	O
,	O
this	O
allows	O
string	O
concatenation	O
in	O
early	O
phases	O
of	O
compilation	O
(	O
"	O
translation	O
"	O
,	O
specifically	O
as	O
part	O
of	O
lexical	B-Application
analysis	I-Application
)	O
,	O
without	O
requiring	O
phrase	O
analysis	O
or	O
constant	O
folding	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
following	O
are	O
valid	O
C/C	O
++	O
:	O
</s>
<s>
This	O
is	O
because	O
string	B-Language
literals	I-Language
have	O
array	O
type	O
,	O
char	O
 [ n ] 	O
(	O
C	B-Language
)	O
or	O
const	O
char	O
 [ n ] 	O
(	O
C++	O
)	O
,	O
which	O
cannot	O
be	O
added	O
;	O
this	O
is	O
not	O
a	O
restriction	O
in	O
most	O
other	O
languages	O
.	O
</s>
<s>
This	O
is	O
particularly	O
important	O
when	O
used	O
in	O
combination	O
with	O
the	O
C	B-Language
preprocessor	I-Language
,	O
to	O
allow	O
strings	O
to	O
be	O
computed	O
following	O
preprocessing	O
,	O
particularly	O
in	O
macros	O
.	O
</s>
<s>
will	O
(	O
if	O
the	O
file	O
is	O
called	O
a.c	O
)	O
expand	O
to	O
:	O
</s>
<s>
A	O
common	O
use	O
case	O
is	O
in	O
constructing	O
printf	B-Language
or	O
scanf	O
format	B-Language
strings	I-Language
,	O
where	O
format	B-Language
specifiers	I-Language
are	O
given	O
by	O
macros	O
.	O
</s>
<s>
A	O
more	O
complex	O
example	O
uses	O
of	O
integers	O
(	O
by	O
the	O
preprocessor	O
)	O
to	O
define	O
a	O
macro	O
that	O
expands	O
to	O
a	O
sequence	O
of	O
string	B-Language
literals	I-Language
,	O
which	O
are	O
then	O
concatenated	O
to	O
a	O
single	O
string	B-Language
literal	I-Language
with	O
the	O
file	O
name	O
and	O
line	O
number	O
:	O
</s>
<s>
Beyond	O
syntactic	O
requirements	O
of	O
C/C	O
++	O
,	O
implicit	O
concatenation	O
is	O
a	O
form	O
of	O
syntactic	O
sugar	O
,	O
making	O
it	O
simpler	O
to	O
split	O
string	B-Language
literals	I-Language
across	O
several	O
lines	O
,	O
avoiding	O
the	O
need	O
for	O
line	O
continuation	O
(	O
via	O
backslashes	O
)	O
and	O
allowing	O
one	O
to	O
add	O
comments	O
to	O
parts	O
of	O
strings	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
Python	B-Language
,	O
one	O
can	O
comment	O
a	O
regular	B-Language
expression	I-Language
in	O
this	O
way	O
:	O
</s>
<s>
Accordingly	O
,	O
it	O
is	O
not	O
used	O
in	O
most	O
languages	O
,	O
and	O
it	O
has	O
been	O
proposed	O
for	O
deprecation	O
from	O
D	B-Application
and	O
Python	B-Language
.	O
</s>
<s>
However	O
,	O
removing	O
the	O
feature	O
breaks	O
backwards	O
compatibility	O
,	O
and	O
replacing	O
it	O
with	O
a	O
concatenation	O
operator	O
introduces	O
issues	O
of	O
precedence	O
–	O
string	B-Language
literal	I-Language
concatenation	O
occurs	O
during	O
lexing	B-Application
,	O
prior	O
to	O
operator	O
evaluation	O
,	O
but	O
concatenation	O
via	O
an	O
explicit	O
operator	O
occurs	O
at	O
the	O
same	O
time	O
as	O
other	O
operators	O
,	O
hence	O
precedence	O
is	O
an	O
issue	O
,	O
potentially	O
requiring	O
parentheses	O
to	O
ensure	O
desired	O
evaluation	O
order	O
.	O
</s>
<s>
A	O
subtler	O
issue	O
is	O
that	O
in	O
C	B-Language
and	O
C++	O
,	O
there	O
are	O
different	O
types	O
of	O
string	B-Language
literals	I-Language
,	O
and	O
concatenation	O
of	O
these	O
has	O
implementation-defined	O
behavior	O
,	O
which	O
poses	O
a	O
potential	O
security	O
risk	O
.	O
</s>
<s>
Most	O
often	O
this	O
is	O
done	O
by	O
changing	O
the	O
quoting	B-Language
character	O
or	O
adding	O
a	O
prefix	O
or	O
suffix	O
.	O
</s>
<s>
One	O
of	O
the	O
oldest	O
examples	O
is	O
in	O
shell	O
scripts	O
,	O
where	O
single	O
quotes	O
indicate	O
a	O
raw	O
string	O
or	O
"	O
literal	B-Language
string	I-Language
"	O
,	O
while	O
double	O
quotes	O
have	O
escape	O
sequences	O
and	O
variable	O
interpolation	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
Python	B-Language
,	O
raw	O
strings	O
are	O
preceded	O
by	O
an	O
r	O
or	O
R	O
–	O
compare	O
'	O
C:\\Windows	O
 '	O
with	O
r'C:\Windows'	O
(	O
though	O
,	O
a	O
Python	B-Language
raw	O
string	O
cannot	O
end	O
in	O
an	O
odd	O
number	O
of	O
backslashes	O
)	O
.	O
</s>
<s>
Python	B-Language
2	O
also	O
distinguishes	O
two	O
types	O
of	O
strings	O
:	O
8-bit	O
ASCII	B-Protocol
(	O
"	O
bytes	O
"	O
)	O
strings	O
(	O
the	O
default	O
)	O
,	O
explicitly	O
indicated	O
with	O
a	O
b	O
or	O
B	O
prefix	O
,	O
and	O
Unicode	O
strings	O
,	O
indicated	O
with	O
a	O
u	O
or	O
U	O
prefix	O
.	O
</s>
<s>
while	O
in	O
Python	B-Language
3	O
strings	O
are	O
Unicode	O
by	O
default	O
and	O
bytes	O
are	O
a	O
separate	O
bytes	O
type	O
that	O
when	O
initialized	O
with	O
quotes	O
must	O
be	O
prefixed	O
with	O
a	O
b	O
.	O
</s>
<s>
C#'s	O
notation	O
for	O
raw	O
strings	O
is	O
called	O
@	O
-quoting	O
.	O
</s>
<s>
C++11	B-Language
allows	O
raw	O
strings	O
,	O
unicode	O
strings	O
(	O
UTF-8	O
,	O
UTF-16	O
,	O
and	O
UTF-32	O
)	O
,	O
and	O
wide	O
character	O
strings	O
,	O
determined	O
by	O
prefixes	O
.	O
</s>
<s>
It	O
also	O
adds	O
literals	O
for	O
the	O
existing	O
C++	O
string	O
,	O
which	O
is	O
generally	O
preferred	O
to	O
the	O
existing	O
C-style	O
strings	O
.	O
</s>
<s>
In	O
Tcl	B-Operating_System
,	O
brace-delimited	O
strings	O
are	O
literal	O
,	O
while	O
quote-delimited	O
strings	O
have	O
escaping	O
and	O
interpolation	O
.	O
</s>
<s>
Perl	B-Language
has	O
a	O
wide	O
variety	O
of	O
strings	O
,	O
which	O
are	O
more	O
formally	O
considered	O
operators	O
,	O
and	O
are	O
known	O
as	O
quote	O
and	O
quote-like	O
operators	O
.	O
</s>
<s>
These	O
include	O
both	O
a	O
usual	O
syntax	O
(	O
fixed	O
delimiters	B-Algorithm
)	O
and	O
a	O
generic	O
syntax	O
,	O
which	O
allows	O
a	O
choice	O
of	O
delimiters	B-Algorithm
;	O
these	O
include	O
:	O
</s>
<s>
REXX	B-Language
uses	O
suffix	O
characters	O
to	O
specify	O
characters	O
or	O
strings	O
using	O
their	O
hexadecimal	O
or	O
binary	O
code	O
.	O
</s>
<s>
In	O
some	O
languages	O
,	O
string	B-Language
literals	I-Language
may	O
contain	O
placeholders	B-Language
referring	O
to	O
variables	O
or	O
expressions	O
in	O
the	O
current	O
context	B-Language
,	O
which	O
are	O
evaluated	O
(	O
usually	O
at	O
run	O
time	O
)	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
sh-compatible	B-Device
Unix	I-Device
shells	I-Device
(	O
as	O
well	O
as	O
Perl	B-Language
and	O
Ruby	B-Language
)	O
,	O
double-quoted	O
(	O
quotation-delimited	O
,	O
"	O
)	O
strings	O
are	O
interpolated	O
,	O
while	O
single-quoted	O
(	O
apostrophe-delimited	O
,	O
'	O
)	O
strings	O
are	O
not	O
.	O
</s>
<s>
Non-interpolated	O
string	B-Language
literals	I-Language
are	O
sometimes	O
referred	O
to	O
as	O
"	O
raw	O
strings	O
"	O
,	O
but	O
this	O
is	O
distinct	O
from	O
"	O
raw	O
string	O
"	O
in	O
the	O
sense	O
of	O
escaping	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
Python	B-Language
,	O
a	O
string	O
prefixed	O
with	O
r	O
or	O
R	O
has	O
no	O
escaping	O
or	O
interpolation	O
,	O
a	O
normal	O
string	O
(	O
no	O
prefix	O
)	O
has	O
escaping	O
but	O
no	O
interpolation	O
,	O
and	O
a	O
string	O
prefixed	O
with	O
f	O
or	O
F	O
has	O
escaping	O
and	O
interpolation	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
following	O
Perl	B-Language
code	O
:	O
</s>
<s>
In	O
this	O
case	O
,	O
the	O
metacharacter	B-Algorithm
character	O
( $	O
)	O
(	O
not	O
to	O
be	O
confused	O
with	O
the	O
sigil	O
in	O
the	O
variable	O
assignment	O
statement	O
)	O
is	O
interpreted	O
to	O
indicate	O
variable	O
interpolation	O
,	O
and	O
requires	O
some	O
escaping	O
if	O
it	O
needs	O
to	O
be	O
outputted	O
literally	O
.	O
</s>
<s>
This	O
should	O
be	O
contrasted	O
with	O
the	O
printf	B-Language
function	O
,	O
which	O
produces	O
the	O
same	O
output	O
using	O
notation	O
such	O
as	O
:	O
</s>
<s>
but	O
does	O
not	O
perform	O
interpolation	O
:	O
the	O
%s	B-Language
is	O
a	O
placeholder	B-Language
in	O
a	O
printf	B-Language
format	I-Language
string	I-Language
,	O
but	O
the	O
variables	O
themselves	O
are	O
outside	O
the	O
string	O
.	O
</s>
<s>
Here	O
the	O
$	O
characters	O
are	O
not	O
metacharacters	B-Algorithm
,	O
and	O
are	O
not	O
interpreted	O
to	O
have	O
any	O
meaning	O
other	O
than	O
plain	O
text	O
.	O
</s>
<s>
Languages	O
that	O
lack	O
flexibility	O
in	O
specifying	O
string	B-Language
literals	I-Language
make	O
it	O
particularly	O
cumbersome	O
to	O
write	O
programming	B-General_Concept
code	O
that	O
generates	O
other	O
programming	B-General_Concept
code	O
.	O
</s>
<s>
generating	O
an	O
output	O
language	O
from	O
within	O
a	O
web	B-Application
template	I-Application
;	O
</s>
<s>
generating	O
a	O
PostScript	B-Language
representation	O
of	O
a	O
document	O
for	O
printing	O
purposes	O
,	O
from	O
within	O
a	O
document-processing	O
application	O
written	O
in	O
C	B-Language
or	O
some	O
other	O
language	O
.	O
</s>
<s>
Nevertheless	O
,	O
some	O
languages	O
are	O
particularly	O
well-adapted	O
to	O
produce	O
this	O
sort	O
of	O
self-similar	O
output	O
,	O
especially	O
those	O
that	O
support	O
multiple	O
options	O
for	O
avoiding	O
delimiter	B-Algorithm
collision	O
.	O
</s>
<s>
Using	O
string	B-Language
literals	I-Language
as	O
code	O
that	O
generates	O
other	O
code	O
may	O
have	O
adverse	O
security	O
implications	O
,	O
especially	O
if	O
the	O
output	O
is	O
based	O
at	O
least	O
partially	O
on	O
untrusted	O
user	O
input	O
.	O
</s>
<s>
This	O
is	O
particularly	O
acute	O
in	O
the	O
case	O
of	O
Web-based	O
applications	O
,	O
where	O
malicious	O
users	O
can	O
take	O
advantage	O
of	O
such	O
weaknesses	O
to	O
subvert	O
the	O
operation	O
of	O
the	O
application	O
,	O
for	O
example	O
by	O
mounting	O
an	O
SQL	B-Language
injection	I-Language
attack	I-Language
.	O
</s>
