Literals/String: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
(→{{header|Wren}}: Updated to v0.4.0.) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(26 intermediate revisions by 12 users not shown) | |||
Line 24:
=={{header|11l}}==
Character literals:
<
Regular string literals are enclosed in double quotes, and use \ to delimit special characters:
<
Raw string literals are enclosed in paired single quotation marks:
<
bar’</
If raw string literal should contains unpaired single quotation marks, then balancing of raw string should be performed:
<
=={{header|6502 Assembly}}==
Strings are enclosed in double quotes.
<syntaxhighlight lang="6502asm">db "Hello World"</syntaxhighlight>
Any typed character in double quotes is assembled as the ASCII equivalent of that character. Therefore the following two data blocks are equivalent:
<syntaxhighlight lang="6502asm">db "Hello World"
db $48,$65,$6c,$6c,$6f,$20,$57,$6f,$72,$6c,$64</syntaxhighlight>
When using a single-character literal as an operand for an instruction, it MUST have a # in front, or else the CPU will treat it as a pointer being dereferenced rather than a numeric constant. (We've all made this mistake at least once without realizing it.)
<syntaxhighlight lang="6502asm">LDA #'A' ;load ascii code of "A" into the accumulator.
LDA 'A' ;load the byte stored at memory address 0x41 into the accumulator.</syntaxhighlight>
The assembler typically assumes nothing with regard to special characters. A <code>\n</code> will be interpreted literally, for example. How special characters are handled depends on the printing routine of the hardware's BIOS, or one created by the programmer. If your printing routine is able to support a null terminator and ASCII control codes, the following represents "Hello World" with the new line command and null terminator:
<syntaxhighlight lang="6502asm">db "Hello World",13,10,0</syntaxhighlight>
Creating your own printing routine is a bit out of the scope of this task but here's a simple demonstration that supports the \n and null termination:
<syntaxhighlight lang="6502asm">PrintString:
lda (StringPtr),y
beq Terminated
cmp #'\' ; a single ascii character is specified in single quotes.
beq HandleSpecialChars
jsr PrintChar ;unimplemented print routine
iny ;next character
jmp PrintString ;back to top
Terminated:
rts ;exit
HandleSpecialChars:
iny ;next char
lda (StringPtr),y
cmp #'n'
beq NextLine ;unimplemented new line routine, it ends in "JMP DoneSpecialChar."
;Typically this would reset the x cursor and increment the y cursor, which are software variables that
;get converted to a VRAM address in some other routine.
DoneSpecialChar:
iny
jmp PrintString ;jump back to top. Notice that neither the backslash nor the character after it were actually printed.</syntaxhighlight>
=={{header|68000 Assembly}}==
{{trans|6502 Assembly}}
Strings are enclosed in double quotes. [[C]] places a null terminator at the end of the string for you; in 68000 Assembly you have to type it manually (unless your assembler has an <code>.ASCIZ</code> directive or equivalent, and not all do).
<syntaxhighlight lang="68000devpac">DC.B "Hello World",0
EVEN</syntaxhighlight>
Any typed character in double quotes is assembled as the ASCII equivalent of that character. Therefore the following two data blocks are equivalent:
<syntaxhighlight lang="68000devpac">DC.B "Hello World",0
EVEN
DC.B $48,$65,$6c,$6c,$6f,$20,$57,$6f,$72,$6c,$64,$00
EVEN</syntaxhighlight>
When using a string literal as an operand for an instruction, it must begin with #, otherwise it will be treated as a pointer being dereferenced rather than the numeric constant you intended.
<syntaxhighlight lang="68000devpac">MOVE.L #'SEGA',D0 ;load the string "SEGA" into D0
MOVE.L '0000',D0 ;load the 32-bit value at address 0x00303030 (the most significant byte is always treated as zero,
;because the 68000 only has a 24-bit address space.</syntaxhighlight>
The assembler typically assumes nothing with regard to special characters. How special characters are handled depends on the printing routine of the hardware's BIOS, or in the case of embedded hardware with no BIOS or a very limited one like the Sega Genesis, the printing routine created by the programmer. By default, there is no support for any control codes unless you add it in yourself.
=={{header|Ada}}==
Single character literals require single quotes
<
String literals use double quotes
<
empty : string := ""; -- an empty string</
The length of a string in Ada is equal to the number of characters in the string.
Ada does not employ a terminating null character like C.
Line 53 ⟶ 112:
Aime has no character representation, but it allows single quoted character constants. Their implied typed is integer.
<
c = 'z';</
String literals are double quoted.
<
s = "z";</
=={{header|ALGOL 68}}==
In ALGOL 68 a single character (CHAR), character arrays ([]CHAR) and strings (STRING) are contained in double quotes. ALGOL 68 also has FORMAT strings which are contained between dollar ($) symbols.
<
Strings are contained in double quotes.
<
STRING stringxyz = "xyz";
FORMAT twonewlines = $ll$, threenewpages=$ppp$, fourbackspaces=$bbbb$;</
Note: When only uppercase characters sets are available (eg on computers with only
6 bits per "byte") the single quote can used to denote a reserved word. eg
<
[]'CHAR' CHARXYZ = "XYZ";</
The STRING type is simply a FLEX array of CHAR.
<
ALGOL 68 also has raw strings called BYTES, this type is a fixed width packed array of CHAR.
<
A string quote character is inserted in a string when two quotes are entered, eg:
<
A string can span lines, but cannot contain newlines. String literals are concatenated when compiled:
<
"line Y;" +
"line Z;";</
ALGOL 68 uses FORMATs for doing more advanced manipulations.
For example given:
<
associate(linef, line);</
Instead of using preprocessor macros ALGOL 68 can do FORMAT variable replacement within FORMATs at run time.
<
FORMAT foo = $"prefix_"f(my_symbol)"_suffix"$;
putf(linef ,foo);</
In <b>standard</b> ALGOL 68 a "book" is a file. A book is composed of pages and lines and
therefore a FORMAT be used for inserting backspaces, space, newlines and newpages into books.
<
FILE bookf; FLEX[pages]FLEX[lines]FLEX[characters]CHAR book;
associate(bookf, book);
# following putf inserts the string " Line 4 indented 5" on page 3 #
putf(bookf, $3p"Page 3"4l5x"Line 4 indented 5"$)</
Note: ALGOL 68G does not implement newpage and backspace.
=={{header|ALGOL W}}==
<
% String literals are enclosed in double-quotes in Algol W. %
% There isn't a separate character type but strings of lenghth one can %
Line 120 ⟶ 179:
write( "a\nb" );
end.</
{{out}}
<pre>
Line 130 ⟶ 189:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
/* program stringsEx.s */
Line 209 ⟶ 268:
pop {r0,r1,r2,r7,lr} @ restaur registers
bx lr @ return
</syntaxhighlight>
=={{header|Arturo}}==
<
print [str "->" type str]
Line 236 ⟶ 295:
:}
print [verbatim "->" type verbatim]</
{{out}}
Line 252 ⟶ 311:
=={{header|AutoHotkey}}==
unicode
<
"text" ; string
hereString = ; with interpolation of %variables%
Line 264 ⟶ 323:
(Comments %
literal %A_Now% ; no interpolation here
)</
=={{header|AWK}}==
In awk, strings are enclosed using doublequotes.
Characters are just strings of length 1.
<
str= "hello"
s1 = "abcd" # simple string
s2 = "ab\"cd" # string containing a double quote, escaped with backslash
print s1
print s2 </
{{out}} Concatenation
<
hellox</
=={{header|Axe}}==
Character literal:
<syntaxhighlight lang
String literal:
<
Note that string literals are only null-terminated if they are assigned to a variable (e.g. Str1).
Line 295 ⟶ 354:
Here we use the ASCII code for doublequotes to get the characters into a string:
<
20 LET D$=Q$+Q$: REM A PAIR OF DOUBLEQUOTES
30 LET S$=Q$+"THIS IS A QUOTED STRING"+Q$
40 PRINT Q$;"HELLO";Q$:REM ADD QUOTES DURING OUTPUT</
''Most'' modern BASIC implementations don't differentiate between characters and strings -- a character is just a string of length 1.
Line 308 ⟶ 367:
Strings can optionally be declared as being a certain length, much like C strings.
<
c = "char" 'everything after the first character is silently discarded
s = "string"
PRINT CHR$(34); s; " data "; c; CHR$(34)</
{{out}}
Line 318 ⟶ 377:
==={{header|Applesoft BASIC}}===
<
A$ = "THERE ARE" + M$
A$ = A$ + "NO " + Q$ + "HERE" + Q$ + " STRINGS."
? A$</
==={{header|IS-BASIC}}===
<
110 PRINT """"
120 PRINT "This is a ""quoted string""."</
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">
print "Hello, World."
print chr(34); "Hello, World." & chr(34)
print "Tom said," + "'The fox ran away.'"
</syntaxhighlight>
==={{header|ZX Spectrum Basic}}===
Line 341 ⟶ 400:
by adding an extra pair of doublequotes:
<
10 REM Print some quotes
20 PRINT CHR$(34)
Line 348 ⟶ 407:
50 REM Output the word hello enclosed in doublequotes
60 PRINT """Hello"""
</syntaxhighlight>
==={{header|uBasic/4tH}}===
uBasic/4tH supports the inclusion of doublequotes by allowing the escape <code>\q</code> in almost every string literal.
<syntaxhighlight lang="text">Print "This is a ";Chr(Ord("\q"));"quoted string";Chr(Ord("\q"))
Print "This is a \qquoted string\q"
a := "This is a \qquoted string\q" : Print Show(a)
</syntaxhighlight>
=={{header|BBC BASIC}}==
Line 355 ⟶ 422:
There is no special representation for a single character (it is just a string of length one).
'Here strings' are not supported.
<
{{out}}
<pre>
Line 372 ⟶ 439:
which may be pushed using <tt>57*1-</tt>.
Note: since you are pushing the string onto a stack, you usually want to define the string in reverse order so that the first character is on top.
<
=={{header|Bracmat}}==
Line 403 ⟶ 470:
In C, single characters are contained in single quotes.
<
Strings are contained in double quotes.
<
This means that 'z' and "z" are different.
Line 415 ⟶ 482:
A string can span lines. Newlines can be added via backslash escapes, and string literals are concatenated when compiled:
<
"line 2\n"
"line 3\n";</
C can use library functions such as ''sprintf'' for doing formatted replacement within strings at run time, or preprocessor concatenation to build string literals at compile time:
<
=={{header|C sharp|C#}}==
Line 428 ⟶ 495:
'''C#''' supports verbatim strings. These begin with @" and end with ". Verbatim quotes may contain line breaks and so verbatim strings and here-strings overlap.
<
string multiline = @"Line 1.
Line 2.
Line 3.";</
=={{header|C++}}==
Line 439 ⟶ 506:
In C++11, it is also possible to use so-called "Raw Strings":
<
a newline-separated
raw string)";
</syntaxhighlight>
=={{header|Clojure}}==
Character literals are prefixed by a backslash:
<
\uXXXX ; where XXXX is some hex Unicode code point
\\ ; the backslash character literal</
There are also identifiers for special characters:
<
\newline
\tab
\formfeed
\return
\backspace</
Clojure strings ''are'' Java Strings, and literals are written in the same manner:
<
=={{header|COBOL}}==
Strings can be enclosed in either single quotes or double quotes. There is no difference between them.
<
'As is this.'</
Character literals are strings of two-digit hexadecimal numbers preceded by an x.
<
X"48656C6C6F21" *> "Hello!"</
There are also figurative constants which are equivalent to certain string literals:
<
LOW-VALUE LOW-VALUES *> " " X"00".
NULL *> " " X"00".
QUOTE QUOTES *> " " double-quote character.
SPACE SPACES *> " " space.
ZERO ZEROS ZEROES *> " " zero.</
=={{header|Common Lisp}}==
Character literals are referenced using a hash-backslash notation. Strings are arrays or sequences of characters and can be declared using double-quotes or constructed using other sequence commands.
<
(str "http://www.rosettacode.com/"))
(format t "colon found at position ~d~%" (position colon str)))</
=={{header|D}}==
Character literals:
<
Regular strings support C-style escape sequences.
<
auto str2 = "hello"c; // UTF-8
auto str3 = "hello"w; // UTF-16
auto str4 = "hello"d; // UTF-32</
Literal string (escape sequences are not interpreted):
<
auto str2 = r"\n is slash-n";</
Specified delimiter string:
<
// the string ends with that same character followed
// by a quote.
auto str = q"$"Hello?" he enquired.$";</
<
auto otherStr = q"EOS
This is part of the string.
So is this.
EOS";</
Token string:
<
auto str = q{int i = 5;};
// The contents here isn't a legal token in D, so it's an error:
auto illegal = q{@?};</
Hex string:
<
auto str = x"68 65 6c 6c 6f";</
=={{header|Delphi}}==
<syntaxhighlight lang="delphi">var
lChar: Char;
lLine: string;
Line 532 ⟶ 599:
lChar := 'a';
lLine := 'some text';
lMultiLine := 'some text' + #13#10 + 'on two lines';</
=={{header|DWScript}}==
Strings are either single or double quote delimited, if you want to include the delimiter in the string, you just double it.
Specific character codes (Unicode) can be specified via # (outside of the string).
<
const s1 := 'quoted "word" in string';
const s2 := "quoted ""word"" in string"; // sames as s1, shows the doubling of the delimiter
const s2 := 'first line'#13#10'second line'; // CR+LF in the middle
</syntaxhighlight>
=={{header|Dyalect}}==
Line 547 ⟶ 614:
Strings in Dyalect are double quote delimited (and characters are single quote delimited). Both support escape codes:
<
Dyalect also supports multiline strings:
<syntaxhighlight lang="dyalect">let long_str = <[first line
second line
third line]></syntaxhighlight>
Multiline strings do not support escape codes.
=={{header|Déjà Vu}}==
<
local :s2 "newline \n carriage return \r tab \t"
!print "backslash \\ quote \q decimal character \{8364}"</
{{out}}
<pre>backslash \ quote " decimal character €</pre>
Line 563 ⟶ 636:
E has three sorts of quotes: ''strings'', ''characters'', and ''quasiliterals''.
<
"The quick brown fox" # string
`The $kind brown fox` # "simple" quasiliteral
term`the($adjectives*, fox)` # "term" quasiliteral</
Strings and characters use syntax similar to Java; double and single quotes, respectively, and common backslash escapes.
Line 574 ⟶ 647:
Quasiliterals can be used for strings as well. The third example above is the built-in simple interpolator, which also supports pattern matching. There is also a regular-expression quasi-pattern:
<
# value: ["abc", "def"]
? if (" >abc, def< " =~ rx`\W*(@a\w+)\W+(@b\w+)\W*`) { [a, b] } else { null }
# value: ["abc", "def"]</
=={{header|EasyLang}}==
Strings are always enclosed in double quotes ("). Unicode is also supported.
<syntaxhighlight lang="easylang">
print "EasyLang"
print "简"
</syntaxhighlight>
=={{header|Ela}}==
Ela has both characters:
<
and strings:
<
Both support C-style escape codes:
<
str = "first line\nsecond line\nthird line"</
Also Ela supports verbatim strings with the following syntax:
<
verbatim string]></
=={{header|Elena}}==
ELENA 4.x :
<
var c := $65; // character
var s := "some text"; // UTF-8 literal
Line 600 ⟶ 680:
var s2 := "text with ""quotes"" and
two lines";
</syntaxhighlight>
=={{header|Elixir}}==
===String===
Strings are between double quotes; they're represented internally as utf-8 encoded bytes and support interpolation.
<syntaxhighlight lang="elixir">
IO.puts "Begin String \n============"
str = "string"
str |> is_binary # true
</syntaxhighlight>
While internally represented as a sequence of bytes, the String module splits the codepoints into strings.
<syntaxhighlight lang="elixir">
str |> String.codepoints
</syntaxhighlight>
The bytes can be accessed by appending a null byte to the string
<syntaxhighlight lang="elixir">
str <> <<0>>
</syntaxhighlight>
Strings can be evaluated using <code>?</code> before a character in the command line or in a string, then evaluating the string
<syntaxhighlight lang="elixir">
?a # 97
Code.eval_string("?b") # 98
Code.eval_string("?ł") # 322
</syntaxhighlight>
===Char Lists===
Char lists are simply lists of characters. Elixir will attempt to convert number values to characters if a string could be formed from the values. Char lists represent characters as single quotes and still allow for interpolation.
<syntaxhighlight lang="elixir">
IO.inspect "Begin Char List \n============="
[115, 116, 114, 105, 110, 103]
ch = "hi"
'string #{ch}'
</syntaxhighlight>
Again, since 0 cannot be rendered as a character, adding it to a char list will return the char list
<syntaxhighlight lang="elixir">
'string #{ch}'++[0]
</syntaxhighlight>
{{out}}
Line 658 ⟶ 738:
The only string literal is a double-quote
<
Backslash gives various special characters similar to C, such as
Line 669 ⟶ 749:
was a separate type.) <code>?</code> is the read syntax.
<
?\n ;=> 10</
See "Basic Char Syntax" in the elisp manual.
Line 676 ⟶ 756:
=={{header|Erlang}}==
Erlang strings are lists containing integer values within the range of the ASCII or (depending on version and settings) Unicode characters.
<
"This is a string".
[$T,$h,$i,$s,$ ,$a,$ ,$s,$t,$r,$i,$n,$g,$,,$ ,$t,$o,$o].
</syntaxhighlight>
Characters are represented either as literals (above) or integer values.
<
97 == $a. % => true
</syntaxhighlight>
With the string syntax, characters can be escaped with \.
<
"\"The quick brown fox jumps over the lazy dog.\"".
</syntaxhighlight>
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
let n= 'N'
let i="Name=\"Nigel Galloway\"\n"
let g= @"Name=""Nigel Galloway""\n"
let e="Nigel
Galloway"
let l= """Name="Nigel Galloway"\n"""
printfn "%c\n%s\n%s\n%s\n%s" n i g e l
</syntaxhighlight>
{{out}}
<pre>
N
Name="Nigel Galloway"
Name="Nigel Galloway"\n
Nigel
Galloway
Name="Nigel Galloway"\n
</pre>
=={{header|Factor}}==
A basic character:
<syntaxhighlight lang
Characters are Unicode code points (integers in the range <tt>[0-2,097,152]</tt>).
<code>CHAR:</code> is a parsing word that takes a literal character, escape code, or Unicode code point name and adds a Unicode code point to the parse tree.
<
CHAR: \u000032 ! 50
CHAR: \u{exclamation-mark} ! 33
CHAR: exclamation-mark ! 33
CHAR: ugaritic-letter-samka ! 66450</
Strings are represented as fixed-size mutable sequences of Unicode code points.
A basic string:
<
We can take a look under the hood:
<
Both <code>CHAR:</code> and strings support the following escape codes:
Line 760 ⟶ 860:
Some examples of strings with escape codes:
<
{{out}}
<pre>
Line 767 ⟶ 867:
</pre>
Putting quotation marks into a string:
<
{{out}}
<pre>
Line 773 ⟶ 873:
</pre>
Strings can span multiple lines. Newlines are inserted where they occur in the literal.
<
2\u{superscript-three} = 8
2\u{superscript-four} = 16" print</
{{out}}
<pre>
Line 785 ⟶ 885:
A verbatim string:
<
[[ escape codes \t are literal \\ in here
but newlines \u{plus-minus-sign} are still
inserted " for each line the string \" spans.]] print</
{{out}}
<pre>
Line 798 ⟶ 898:
A here-string:
<
HEREDOC: END
Everything between the line above
Line 805 ⟶ 905:
is significant.
END
print</
{{out}}
<pre>
Line 815 ⟶ 915:
</pre>
<code>STRING:</code> is similar to <code>HEREDOC:</code> except instead of immediately placing the string on the data stack, it defines a word that places the string on the data stack when called.
<
STRING: random-stuff
ABC
Line 821 ⟶ 921:
"x y z
;
random-stuff print</
{{out}}
<pre>
Line 830 ⟶ 930:
Finally, the <code>interpolate</code> vocabulary provides support for interpolating lexical variables, dynamic variables, and data stack values into strings.
<
"Sally" "name" set
Line 844 ⟶ 944:
I]
]</
{{out}}
<pre>
Line 854 ⟶ 954:
=={{header|Forth}}==
In the interpreter:
<
s" string" type</
In the compiler:
<
[char] c emit
s" string" type ;</
Strings may contain any printable character except a double quote, and may not span multiple lines. Strings are done via the word S" which parses ahead for a terminal quote. The space directly after S" is thus not included in the string.
Line 865 ⟶ 965:
GNU Forth has a prefix syntax for character literals, and another string literal word S\" which allows escaped characters, similar to [[C]].
<
s\" hello\nthere!"</
=={{header|Fortran}}==
First Fortran (1958) did not offer any means to manipulate text except via the H (for Hollerith) code in FORMAT statements of the form nH where n was an integer that counted the ''exact'' numbers of characters following the H, any characters, that constituted the text literal. Miscounts would cause a syntax error, if you were lucky. This would be used for output to annotate the numbers, but consider the following: <
PRINT 1
1 FORMAT (12HElement Name,F9.4)
Line 875 ⟶ 975:
READ 1,ATWT(I)
10 PRINT 1,ATWT(I)
END </
Evidently, the syntax highlighter here does not recognise the Hollerith style usage. Nor do some compilers, even if in its original home within FORMAT statements.
The first PRINT statement writes out a heading, here with lower case letters as an anachronism. Then the loop reads a deck of cards containing the name of an element and its atomic weight into an array ATWT, but the special feature is that the first twelve characters of each card replace the text in the FORMAT statement, and thus the following PRINT statement shows the name of the element followed by its atomic weight as just read.
Fortran IV introduced a text literal, specified within apostrophes, with two apostrophes in a row indicating an apostrophe within the text. Later, either an apostrophe or a double quote could be used to start a text string (and the same one must be used to end it) so that if one or the other were desired within a text literal, the other could be used as its delimiters. If both were desired, then there would be no escape from doubling for one. Because spaces are significant within text literals, a long text literal continued on the next line would have the contents of column seven of the continuation line immediately following the contents of column 72 of the continued line - except that (for some compilers reading disc files) if such lines did not extend to column 72 (because trailing spaces were trimmed from the records) rather less text would be defined. So, even though this is in fixed-format (or card image) style, again misinterpreted by the syntax highlighter, <
1Stuff"</
might be the equivalent of only <code>BLAH = "Stuff"</code> instead of defining a text literal with many leading spaces. F90 formalised an opportunity for free-format source files; many compilers had also allowed usage beyond column 72.
Within the text literal, any character whatever may be supplied as text grist, according to the encodement recognised by the card reader as this was a fixed-format file - cards have an actual physical size. This applied also to source text held in disc files, as they were either fixed-size records or, for variable-length records, records had a length specification and the record content was not involved. Variable-length records were good for omitting the storage of the trailing spaces on each line, except that the sequence numbers were at the end of the line! In this case they might be omitted (unlike a card deck, a disc file's records are not going to be dropped) or there may be special provision for them to be at the start of each line with the source text's column one staring in column nine of the record. But, for the likes of paper tape, the question "How long is a record?" has no natural answer, and record endings were marked by a special symbol. Such a symbol (or symbol sequence) could not appear within a record, such as within a text literal and be taken as a part of the text. This style has been followed by the ASCII world, with variously CR, CRLF, LFCR and CR sequences being used to mark end-of-record. Such characters cannot be placed within a text literal, but the CHAR(n) function makes them available in character expressions. Some compilers however corrupt the "literal" nature of text ''literals'' by allowing escape sequences to do so, usually in the style popularised by C, thus \n, and consequently, \\ should a single \ be desired.
Some examples, supposing that TEXT is a CHARACTER variable. <
TEXT = "That's right!" !Chose quotes, so that apostrophes may be used freely.
TEXT = "He said ""That's right!""" !Give in, and use quotes for a "quoted string" source style.
TEXT = 'He said "That''s right!"' !Though one may dabble in inconsistency.
TEXT = 23HHe said "That's right!" !Some later compilers allowed Hollerith to escape from FORMAT. </
A similar syntax enables the specification of hexadecimal, octal or binary sequences, as in <code>X = Z"01FE"</code> for hexadecimal (the "H" code already being used for "Hollerith" even if the H-usage is not supported by the compiler) but this is for numerical values, not text strings. While one could mess about with EQUIVALENCE statements, numbers fill up from the right while text strings fill from the left and there would be "endian" issues as well, so it is probably not worth the bother. Just use the CHAR function in an expression, as in
<
Which may or may not be acted upon by the output device. A lineprinter probably would ignore a linefeed character but a teletype would not - it would roll the printing carriage one line up without returning to the column one position, thus the usage LFCR (or CRLF) to add the carriage return action. Some systems regard the LF as also implying a CR and for these the notation \n for "newline" is mnemonic even though there is no "newline" character code in ASCII - though there is in EBCDIC. Display screens do not handle glyph construction via overprinting though teletypes (and lineprinters) do. Similarly, a display screen may or may not start a new screen with a formfeed character and a lineprinter won't start a new page - at least if attached to a mainframe computer.
=={{header|FreeBASIC}}==
<
Print "Hello, World."
Print Chr(34); "Hello, World." & Chr(34)
Line 903 ⟶ 1,003:
Print "Tom said, ""The fox ran away."""
Print "Tom said," + "'The fox ran away.'"
</syntaxhighlight>
=={{header|friendly interactive shell}}==
<
echo
echo 'But they are when using either of these characters (or whitespace):'
Line 915 ⟶ 1,015:
echo
set something variable
echo "Double quotes interpolates \\, \" and \$ sequences and $something accesses."</
=={{header|FurryScript}}==
Line 926 ⟶ 1,026:
All three kinds are string literals.
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
@"Hello, world!"
</syntaxhighlight>
=={{header|GAP}}==
<
# true
IsString("abc");
Line 935 ⟶ 1,040:
# false
IsChar("a");
# false</
=={{header|gecho}}==
<syntaxhighlight lang
Just one character.
<syntaxhighlight lang
A string.
Line 948 ⟶ 1,053:
In Go, character literals are called "rune literals" and can be any single valid Unicode code point.
They are written as an integer value or as text within single quotes.
<
ch = 122 // or 0x7a or 0172 or any other integer literal
ch = '\x7a' // \x{2*hex}
ch = '\u007a' // \u{4*hex}
ch = '\U0000007a' // \U{8*hex}
ch = '\172' // \{3*octal}</
A rune literal results in an untyped integer.
When used in a typed constant or stored in a variable, usually the type is either <code>byte</code> or <code>rune</code> to distinguish character values from integer values.
These are aliases for <code>uint8</code> and <code>int32</code> respectively, but like other integer types in Go, they are distinct and require an explicate cast.
<
var r rune = 'z' // r is type rune
var b byte = 'z' // b is type byte (an uint8 type)
Line 971 ⟶ 1,076:
r = rune(c)
i = int(c)
b3 := c // equivalent to b</
Strings literals are are either interpreted or raw.
Line 977 ⟶ 1,082:
Interpreted string literals are contained in double quotes.
They may not contain newlines but may contain backslash escapes.
<
str = "\u007a"
str = "two\nlines"</
This means that 'z' and "z" are different. The former is a character while the latter is a string.
Line 985 ⟶ 1,090:
Unicode may be included in the string literals.
They will be encoded in UTF-8.
<
Raw string literals are contained within back quotes.
They may contain any character except a back quote.
Backslashes have no special meaning.
<
Raw string literals, unlike regular string literals, may also span multiple lines.
The newline is included in the string (but not any <code>'\r'</code> characters):
<
def` == "abc\ndef", // never "abc\r\ndef" even if the source file contains CR+LF line endings</
Go raw string literals serve the purpose of here-strings in other languages.
Line 1,004 ⟶ 1,109:
In [[Groovy]], unlike in [[Java]], a String literal is delimited with ''single quotes'' (apostrophes(')).
<
There is a ''double quote'' (quotation mark(")) delimited syntax in Groovy, but it represents an expression construct called a ''GString'' (I know, I know). Inside of a GString, sub-expression substitution of the form ${''subexpression''} may take place. Thus the following results:
<
println gString
//Outputs:
//Able was I ere I saw Elba</
[[UNIX Shell]] command line users should recognize these forms of syntax as ''strong'' ('-delimited) and ''weak'' ("-delimited) quoting.
And like [[UNIX Shell]] weak quoting syntax, the evaluated subexpression part of the GString syntax loses its special meaning when preceded by a backslash (\):
<
assert gString2 == '1 + 1 = 2'
def gString3 = "1 + 1 = \${1 + 1}"
assert gString3 == '1 + 1 = ${1 + 1}'</
Groovy also supports multi-line String literals and multi-line GString expressions.
<
A man
A plan
Line 1,044 ⟶ 1,149:
//A canal:
//Panama!
//</
[[UNIX Shell]] programmers should recognize these forms of syntax as similar in function to the strong and weak forms of ''Here Document'' syntax.
Line 1,054 ⟶ 1,159:
However, [[Groovy]] has a special GString syntax that uses slash (/) as a GString delimiter rather that quote ("). In this special syntax, most backslash usages that would require a double backslash in a regular String or GString require only a single backslash (\). This does not create a "regular expression object" (there is not such a thing in [[Groovy]]); however, it does evaluate to form a "regular expression ready" String, as demonstrated in the following:
<
assert regexString == '(\\[[Tt]itle\\]|\\[[Ss]ubject\\])50'</
[[Javascript]] users (and others) will recognize the roots of this "regex-ready" syntax as a feature in their own language.
Line 1,062 ⟶ 1,167:
Since apostrophe is used to delimit String literals, that delimiter syntax is not available, as it is in [[Java]], to denote single character literals (type char or Character). However, single character string literals can be converted to character literals by casting. Shown in the examples below are casting using the ''as'' operator, Java-style parenthetical casting, and forced coercion in the intialization of a variable of type char or Character.
<
assert ('a' as char) instanceof Character
assert ((char)'a') instanceof Character
Line 1,069 ⟶ 1,174:
assert x instanceof Character
Character y = 'b'
assert y instanceof Character && (x+1 == y)</
As in [[Java]], backslash is also used to mask a string delimiter. Thus the following two assignments represent strings containing a single quote and a single apostrophe respectively
<
def apostrophe = '\''</
Of course, if you are not using GString subexpression evaluation, you can just use apostrophe delimiters to contain a quote, or quote delimiters to contain an apostrophe.
<
def apostrophe2 = "'"
assert quote == quote2
assert apostrophe == apostrophe2</
=={{header|Haskell}}==
Line 1,090 ⟶ 1,195:
Strings may be split across lines, even indented, using the 'gap' syntax:
<
\def"
"abc\ndef" == "abc\n\
\def"</
You can also use <tt>\&</tt> which expands into nothing (but can be useful to interrupt another escape sequence).
Line 1,104 ⟶ 1,209:
using [http://hackage.haskell.org/package/raw-strings-qq-1.0.2/docs/Text-RawString-QQ.html raw-strings-qq] package:
<
{-# LANGUAGE QuasiQuotes #-}
import Text.RawString.QQ
Line 1,110 ⟶ 1,215:
"abc\ndef" == [r|abc
def|]
</syntaxhighlight>
=={{header|HicEst}}==
HicEst makes no distinction between single characters and strings. One can use single quotes, or double quotes, or most non-standard characters.
<
CHARACTER str1='single quotes', str2="double quotes", str3*100
str3 = % delimit "Nested 'strings' " if needed % </
A null character CHAR(0) is printed as " ", displayed as "." in dialogs, but ends the string in Windows controls such as StatusBar or ClipBoard
<
Named literal constants in HicEst:
<
$LF == CHAR(10)
$CR == CHAR(13)
$CRLF == CHAR(13) // CHAR(10) ! concatenation</
=={{header|Icon}} and {{header|Unicon}}==
Below is a little program to demonstrate string literals.
<
# strings are variable length are not NUL terminated
Line 1,141 ⟶ 1,246:
every x := c1|s1|s2 do # show them
write(" size=",*x,", type=", type(x),", value=", image(x))
end</
{{out}}
Line 1,152 ⟶ 1,257:
The single and double quotes are fairly interchangeable allowing one to use whichever isn't to be quoted (though single-quotes seem more well-behaved around integers in strings). Thus the following are both valid character-constant assignments:
<
b = ' a "string" is this '</
In a pinch, a character constant doesn't absolutely have to be terminated, rendering the following valid:
<
Duplicating either of them quotes them. Thus the following contains three single quotes and no double-quotes:
<
print,a
;==> that's a string</
Things in quotes are not expanded. To get to the content of a variable, leave it unquoted:
<
a = b+' world
print,a
;==> hello world</
Single-quoted strings of valid hex or octal digits will be expanded if followed by "x" or "o":
<
;==> 1911
print,'777'o
;==> 511
print,'777'
;==> 777</
so will be unterminated double-quoted strings if they represent valid octal numbers:
<
;==> 511
print,"877
;==> 877</
Note that this renders the following false (common trip-up for IDL newbies):
<
;==> Syntax error.</
...because the number zero indicates that an octal number follows, but the second double-quote is not a valid octal digit.
Line 1,197 ⟶ 1,302:
Byte-arrays that are converted into strings are converted to the ascii-characters represented by the bytes. E.g.
<
=={{header|Inform 7}}==
String literals are enclosed in double quotes. These may include raw line breaks, or expressions to be substituted enclosed in square brackets.
<
...with your [number of animals in Home] pet[s]."</
Single quotes in a string are translated to double quotes when they occur outside of a word: the string literal <
will print as
<pre>"That's nice," said the captain.</pre>
Line 1,212 ⟶ 1,317:
Raw linebreak must be double -- single linebreaks will be collapsed unless explicitly marked with `[line break]`. In addition, leading whitespace is stripped from each line. This:
<
\
\
\
\"</
will print as:
<pre>\\\\
Line 1,222 ⟶ 1,327:
while this:
<
[line break]\
[line break] \
[line break] \
[line break] \"</
will insert line breaks and preserve the following whitespace, printing as:
<pre>
Line 1,243 ⟶ 1,348:
Examples:
<
'string' NB. List of characters, i.e. a string
'can''t get simpler' NB. Embedded single-quote</
Like VB, J can include newlines and other special characters in literals with concatentation. Also like VB, J comes with certain constants predefined for some characters:
<
'On a mac, you need',CR,'a carriage return'
Line 1,255 ⟶ 1,360:
'And on windows, ',CRLF,'you need both'
TAB,TAB,TAB,'Everyone loves tabs!'</
These constants are simply names assigned to selections from the ASCII alphabet. That is, the standard library executes lines like this:
<
LF =: 10 { a.
CRLF =: CR,LF NB. Or just 10 13 { a.
TAB =: 9 { a.</
Since these constants are nothing special, it can be seen that any variable can be similarly included in a literal:
<
'Hello, ',NAME,' you may have already won $1,000,000'</
For multiline literals, you may define an explicit noun, which is terminated by a lone <code>)</code>
<
Hello, NAME.
Line 1,279 ⟶ 1,384:
To collect your winnings, please send $PAYMENT
to ADDRESS.
)</
Simple substitution is most easily effected by using loading a standard script:
<
name =: 'John Q. Public'
Line 1,294 ⟶ 1,399:
sources =: ":&.> name;shyster;amount;payment;address
message =: template rplc targets,.sources</
While C-like interpolation can be effected with another:
<
'This should look %d%% familiar \nto programmers of %s.' sprintf 99;'C'
This should look 99% familiar
to programmers of C.</
=={{header|Java}}==
<
String b = "abc"; // prints as: abc
char doubleQuote = '"'; // prints as: "
char singleQuote = '\''; // prints as: '
String singleQuotes = "''"; // prints as: ''
String doubleQuotes = "\"\""; // prints as: ""</
Null characters ('\0') are printed as spaces in Java. They will not terminate a String as they would in C or C++. So, the String "this \0is \0a \0test" will print like this:
Line 1,323 ⟶ 1,428:
Unicode characters can be entered as literals or as 4 character hexadecimal escapes. The following expressions are equivalent:
<
return "αβγδ 中间来点中文 🐫 אבגד"
})();
Line 1,330 ⟶ 1,435:
(function() {
return "\u03b1\u03b2\u03b3\u03b4 \u4e2d\u95f4\u6765\u70b9\u4e2d\u6587 \ud83d\udc2b \u05d0\u05d1\u05d2\u05d3";
})();</
Note that in the case of the Emoji character above, where more than 4 hexadecimal characters are needed, ES5 requires us to separately write a pair of surrogate halves, and the '''String.length''' of such characters is 2.
Line 1,339 ⟶ 1,444:
ES6 also introduces template literals, which are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them. Template literals are enclosed by the backtick (<code>` `</code>) (grave accent) character instead of double or single quotes.
<
string text line 2`
const expression = `expressions are also supported, using \$\{\}: ${multiLine}`
console.log(expression)</
{{out}}
<pre>
Line 1,367 ⟶ 1,472:
=={{header|Julia}}==
Concatenation:
<
whom = "world"
greet * ", " * whom * "."</
Interpolation:
<
Both will output:
<syntaxhighlight lang
Triple-quoted strings
<
world.
"""
print(str)</
Will output:
<
world.</
=={{header|Kotlin}}==
Line 1,400 ⟶ 1,505:
Here are some examples of these :
<
fun main(args: Array<String>) {
Line 1,425 ⟶ 1,530:
println(rsl)
println(msl)
}</
{{out}}
Line 1,455 ⟶ 1,560:
===Quoted Strings===
<
"I'm a 2\" string\n"</
===Ticked Strings===
In the below example here \n would not be a line feed, it represents a backslash and n.
<
=={{header|LaTeX}}==
Line 1,470 ⟶ 1,575:
For example, to typeset 'a' is for "apple" in LaTeX, one would type
<
\begin{document}
`a' is for ``apple"
\end{document}</
One common mistake is to use the same symbol for opening and closing quotes,
Line 1,481 ⟶ 1,586:
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
'Liberty BASIC does not support escape characters within literal strings.
print "Quotation mark:"
Line 1,491 ⟶ 1,596:
'Print literal string displaying quotation marks.
print chr$(34) + "Hello, World." + chr$(34)
</syntaxhighlight>
=={{header|Lingo}}==
* Lingo only supports single quotes for string literals. Single quotes inside string literals have to be replaced by ""E&":
<
put str
-- "Hello "world!""</
* Lingo does not support heredoc syntax, but only multiline string literals by using the line continuation character "\":
<
This is the second line.\
This is the third line."</
* Lingo does not support automatic variable expansion in strings. But the function value() can be used to expand template strings in the current context:
<
-- expand template in current context
str = value(template)
put str
-- "Milliseconds since last reboot: 20077664"</
=={{header|Lisaac}}==
Characters:
<
c2 := '\n'; // newline
c3 := '\''; // quote
Line 1,520 ⟶ 1,625:
c5 := '\10\'; // decimal
c6 := '\0Ah\'; // hexadecimal
c7 := '\10010110b\'; // binary</
Strings:
<
s2 := "\""; // double quote
s3 := "abc\
\xyz"; // "abcxyz", cut the gap</
=={{header|LiveCode}}==
LiveCode has only one string representation using quotes. Characters are accessed through chunk expressions, specifically char. Some special characters are built-in constants such as quote, space, comma, cr, return. There is no support for escaping characters or multiline literals.<
put char 1 of "Literal string" -- L
put char 1 to 7 of "Literal string" -- Literal
put word 1 of "Literal string" -- Literal
put quote & "string" & quote -- "string"</
=={{header|Logo}}==
Logo does not have a string or character type that is separate from its symbol type ("word"). A literal word is specified by prefixing a double-quote character.
Reserved and delimiting characters, ()[];~+-*/\=<>| and newline, may be used if preceded by a backslash. Alternatively, the string may be wrapped in vertical bars, in which case only backslash and vertical bar need be escaped.
<
print "|Hello, world|</
=={{header|Lua}}==
Line 1,546 ⟶ 1,651:
to be embedded within a string enclosed with the other symbol.
<
doublequotestring = "can contain 'single quotes'"
longstring = [[can contain
newlines]]
longstring2 = [==[ can contain [[ other ]=] longstring " and ' string [===[ qualifiers]==]</
Note that interpolation of variables names within a string does not take place.
Line 1,557 ⟶ 1,662:
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
Print "Hello {World}"
Print {Hello "World"}
Line 1,565 ⟶ 1,670:
Print """Hello There"""={"Hello There"}
Print Quote$("Hello There")={"Hello There"}
</syntaxhighlight>
=={{header|M4}}==
The quoting characters are <tt>`</tt> and <tt>'</tt>,
but can be changed by the <code>changequote</code> macro:
<syntaxhighlight lang
<
[this is a quoted string]</
=={{header|Maple}}==
There is no separate character type in Maple; a character is just a string of length equal to 1.
<syntaxhighlight lang="maple">
> "foobar";
"foobar"
Line 1,586 ⟶ 1,691:
> "c"; # a character
"c"
</syntaxhighlight>
Note that adjacent strings in the input (separated only by white-space) are concatenated automatically by the parser.
<syntaxhighlight lang="maple">
> "foo" "bar";
"foobar"
</syntaxhighlight>
Since variable names are not distinguished lexically from other text (such as by using a "$" prefix, as in some shells), Maple does not do any kind of variable expansion inside strings.
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
"c"; // String (result: "c")
"\n"; // String (result: newline character)</
=={{header|MATLAB}}==
Strings start and end with single quotes, the escape sequence for a single quote with in a string, is the use of two consequtive single quotes
<syntaxhighlight lang="matlab">
s1 = 'abcd' % simple string
s2 = 'ab''cd' % string containing a single quote
</syntaxhighlight>
{{out}}
<pre>
Line 1,615 ⟶ 1,720:
=={{header|Maxima}}==
<
"The quick brown fox jumps over the lazy dog";
/* A character - just a one character string */
"a"</
=={{header|Metafont}}==
Line 1,625 ⟶ 1,730:
In Metafont there's no difference between a single character string and a single character. Moreover, the double quotes (which delimites a string) cannot be inserted directly into a string; for this reason, the basic Metafont macro set defines
<
i.e. a string which is the single character having ASCII code 34 ("). Macro or variables expansion inside a string block is inhibited.
<
=={{header|ML/I}}==
Line 1,635 ⟶ 1,740:
ML/I treats all input and programs as character streams. Strings do not have to be quoted; they are taken 'as is'. If one wishes to ensure that a string is taken literally (i.e. not evaluated), it is enclosed in ''literal brackets''. There are no predefined literal brackets; the programmer can define anything suitable, usually by setting up a ''matched text skip'', using the MCSKIP operation macro. By convention, the pair <> is used for literal brackets, unless this clashes in the case of a particular processing task.
===Input===
<
"" Literals/String
MCINS %.
Line 1,645 ⟶ 1,750:
"" evaluated.
This is the first mention of Bob
<and here we mention Bob again></
===Output===
<
and here we mention Bob again</
=={{header|MIPS Assembly}}==
{{works with|https://github.com/Kingcom/armips ARMIPS}}
Strings are specified using single or double quotes. The assembler will convert each letter of the string into its ASCII equivalent during the assembly process. Therefore, all of the following statements have the same effect:
<syntaxhighlight lang="mips">li a0,'A'
li a0,0x41
li a0,65
li a0,0b01000001</syntaxhighlight>
This means that you can do compile-time "character addition/subtraction" and the like, to better communicate <i>why</i> your code is doing what it's doing.
<syntaxhighlight lang="mips">;print 0 if $t0 if even, 1 if $t0 is odd
andi t0,t0,1 ;clear all but bit 1. This tells us if $t0 is odd or even.
addiu t0,"0" ;add ASCII 0 (0x30) to $t0
jal PrintChar ;implementation-defined print routine that prints the ASCII value of $t0 to the screen.</syntaxhighlight>
ASCII strings use <code>.byte</code> for declaration. Control codes are implemented by strategically placing commas and their numeric values <i>outside of quotation marks,</i> like so:
<syntaxhighlight lang="mips">MyString:
.byte "Hello World!",13,10,0 ;carriage return, line feed, null terminator
.align 4 ;pads to the next 4 byte-boundary</syntaxhighlight>
As with most RISC CPUs, alignment is a must, especially when working with ASCII strings. ARMIPS doesn't provide alignment automatically, but it does have the <code>.align</code> directive to provide sufficient padding (if necessary) to ensure everything after your string is properly aligned. If it was already aligned, the directive will do nothing rather than burn the bytes, meaning that you don't have to take the time to count how long your string is. There's no memory wasted by dropping a <code>.align</code> after every piece of byte-length data, so might as well.
=={{header|Modula-3}}==
Characters in Modula-3 use single quotes.
<
Strings in Modula-3 use double quotes.
<
<code>TEXT</code> is the string type in Modula-3.
Characters can be stored in an array and then converted to type TEXT using the function <code>Text.FromChars</code> in the <code>Text</code> module.
Strings (of type <code>TEXT</code>) can be converted into an array of characters using the function <code>Text.SetChars</code>.
<
VAR chrarray: ARRAY [1..3] OF CHAR;
Text.SetChars(chrarray, str);
(* chrarray now has the value ['F', 'o', 'o'] *)</
=={{header|MUMPS}}==
Line 1,690 ⟶ 1,820:
Nemerle also has a recursive string literal, enclosed within <# #>, that is the same as a literal string, except that it allows nesting of strings.
<
'\n' // also a character literal
"foo\nbar" // string literal
Line 1,701 ⟶ 1,831:
like "\n".#> // same as "This string type can contain any symbols including \"\nand new lines. "
// + "It does not\nsupport escape codes\nlike \"\\n\"."
<#Test <# Inner #> end#> // same as "Test <# Inner #> end" (i.e. this string type support recursion.</
=={{header|Nim}}==
<
var s = "foobar"
var l = """foobar
Line 1,710 ⟶ 1,840:
more test here"""
var f = r"C:\texts\text.txt" # Raw string</
=={{header|OASYS Assembler}}==
Line 1,727 ⟶ 1,857:
=={{header|Objective-C}}==
The same as C, with the addition of the new string literal
<
which represents a pointer to a statically allocated string object, of type <tt>NSString *</tt>, similar to string literals in Java. You can use this literal like other object pointers, e.g. call methods on it <code>[@"Hello, world!" uppercaseString]</code>.
Line 1,733 ⟶ 1,863:
Characters are contained in single quotes:
<
- : char = 'a'</
Strings are contained in double quotes:
<
- : string = "Hello world"</
Strings may be split across lines and concatenated using the following syntax: (the newline and any blanks at the beginning of the second line is ignored)
<
def";;
- : string = "abcdef"</
If the above syntax is not used then any newlines and whitespace are included in the string:
<
def";;
- : string = "abc\n def"</
Another syntax to include verbatim text:
<
Hello World!
|id} ;;
- : string = "\n Hello World!\n"</
=={{header|Octave}}==
Line 1,760 ⟶ 1,890:
In order to maintain compatible with Matlab,
it is recommended to use single quotes for defining strings.
<syntaxhighlight lang="octave">
s1 = 'abcd' % simple string
s2 = 'ab''cd' % string containing a single quote using an escaped single quote
Line 1,766 ⟶ 1,896:
s4 = "ab'cd" % string containing a single quote
s5 = "ab""cd" % string containing a double quote using an escaped double quote
</syntaxhighlight>
{{out}}
<pre>
Line 1,787 ⟶ 1,917:
There is no character type : characters are integers representing unicode value of the character.
<syntaxhighlight lang="oforth">'a'
'\''
"abcd"
"ab\ncd"
"ab\" and \" cd"</
=={{header|Oz}}==
<
Digit0 = &0 %% the character '0'
NewLine = &\n %% a character with special representation
Line 1,808 ⟶ 1,938:
MyName = "Peter"
MyAge = 8
{System.showInfo MyName # " is " # MyAge # " years old."}</
=={{header|PARI/GP}}==
Line 1,831 ⟶ 1,961:
Double-quotes allows you to interpolate variables and escape sequences, while single-quotes do not.
<
'hello'; # these two strings are the same
"hello";
Line 1,851 ⟶ 1,981:
<<'END'; # Here-Document like single-quoted
Same as above, but no interpolation of $variables.
END</
=={{header|Phix}}==
Line 1,857 ⟶ 1,987:
single character literals (incidentally entirely equivalient to their ascii value) require single quotes, eg
<!--<
<span style="color: #008080;">constant</span> <span style="color: #000000;">UPPERCASEJ</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'J'</span> <span style="color: #000080;font-style:italic;">-- equivalent to 74</span>
<!--</
string literals use double quotes, eg
<!--<
<span style="color: #008080;">constant</span> <span style="color: #000000;">hw</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Hello World!"</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">mt</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span> <span style="color: #000080;font-style:italic;">-- empty string</span>
<!--</
Note that 'z' and "z" are quite different. In Phix there is a strong difference between a character and a string.
All strings are ansi or utf8, depending on the encoding of the source file, eg
<
Utf8 strings are byte-subscripted rather than character-subscripted, so s[3] is not necessarily the third character.<br>
Phix strings have a length field in the (internal) header, /and/ a terminating null, so they can be used directly when interfacing to C-style languages.<br>
Line 1,877 ⟶ 2,007:
Strings are fully mutable: you can append, prepend, replace, substitute, and crop characters and slices (/substrings) any way you like, eg
<!--<
<span style="color: #004080;">string</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"food"</span>
<span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..</span><span style="color: #000000;">3</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'e'</span> <span style="color: #000080;font-style:italic;">-- s is now "feed" (replace all)</span>
<span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"east"</span> <span style="color: #000080;font-style:italic;">-- s is now "feasted" (replace substring)</span>
<span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..</span><span style="color: #000000;">5</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span> <span style="color: #000080;font-style:italic;">-- s is now "fed"</span>
<!--</
Special characters may be entered (between quotes) using a back-slash:
Line 1,905 ⟶ 2,035:
If the literal begins with a newline, it is discarded and any immediately following leading underscores specify a (maximum) trimming that should be applied to all subsequent lines. Examples:
<!--<
<span style="color: #000000;">ts</span> <span style="color: #0000FF;">=</span> ""<span style="color: #008000;">`
this
Line 1,918 ⟶ 2,048:
<span style="color: #000000;">ts</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"this\nstring\\thing"</span>
<!--</
which are all equivalent.
Line 1,928 ⟶ 2,058:
Hex string literals are also supported (mainly for compatibility with OpenEuphoria, x/u/U for 1/2/4 byte codes), eg:
<!--<
<span style="color: #0000FF;">?</span><span style="color: #000000;">x</span><span style="color: #008000;">"68 65 6c 6c 6f"</span><span style="color: #0000FF;">;</span> <span style="color: #000080;font-style:italic;">-- displays "hello"</span>
<!--</
=={{header|PHP}}==
Line 1,939 ⟶ 2,069:
while single-quotes do not.
<
'hello'; # these two strings are the same
"hello";
Line 1,954 ⟶ 2,084:
<<'END' # Here-Document like single-quoted
Same as above, but no interpolation of $variables.
END;</
=={{header|Picat}}==
A string is a list of characters. The string literal is in double quotes (a character is in single quote, e.g 's'):
<pre>"string"</pre>
It can also be constructed as a list of characters:
<pre>['s','t','r','i','n','g']</pre>
or as a list of (character) atoms (without single quotes):
<pre>[s,t,r,i,n,g]</pre>
However, upper case characters must be quoted (otherwise they are considered variables):
<pre>['S',t,r,i,n,g]</pre>
Quoting of certain characters are with an escape character (<code>\c</code>):
<pre>"a string\'s quotes: \"a string\'s quotes\". Spaces: \t\n\l\r"</pre>
A string can be written on several lines where the newlines are kept:
<syntaxhighlight lang="picat"> X = "string with
newlines and
spaces",
% ...
</syntaxhighlight>
Using a single <code>\</code> as the last character on a line makes the line continue without newline.
<syntaxhighlight lang="picat"> X = "string with \
newlines \
and \
spaces",
% ...
</syntaxhighlight>
is the same as
<pre>string with newlines and spaces</pre>
=={{header|PicoLisp}}==
Line 1,961 ⟶ 2,128:
Syntactically, transient symbols (called "strings" in the following) are surrounded by double quotes.
<
-> "ab\"cd"</
Double quotes in strings are escaped with a backslash.
ASCII control characters can be written using the hat ('^') character:
<
There is no special character type or representation. Individual characters are handled as single-character strings:
<
-> ("a" "b" "c")
: (pack (reverse @))
-> "cba"</
A limited handling of here-strings is available with the '[http://software-lab.de/doc/refH.html#here here]' function.
=={{header|Pike}}==
<
'c'; // Character code (ASCII) (result: 99)
"c"; // String (result: "c")
Line 1,984 ⟶ 2,151:
string using the
preprocessor" // single literal string with newlines in it
</syntaxhighlight>
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
'H' /* a single character as a literal. */
'this is a string'
Line 1,994 ⟶ 2,161:
/* stored are <<John's cat>> */
'101100'b /* a bit string, stored as one bit per digit. */
</syntaxhighlight>
=={{header|Plain English}}==
A string literal is surrounded by double quotes. Plain English does not make a distinction between string and character literals.
To escape a double quote inside a string literal, use two double quotes.
<syntaxhighlight lang="text">"a ""string"" literal"</syntaxhighlight>
=={{header|plainTeX}}==
<
\end</
The same as [[Quotes#LaTeX|LaTeX case]], even though one should say the opposite.
Line 2,013 ⟶ 2,186:
String are written in quotes
<
Backslash is used to insert special charaters into strings:
<
=={{header|PowerShell}}==
Line 2,032 ⟶ 2,205:
Standard Prolog has no string types. It has atoms which can be formed in two ways, one of which is wrapping arbitrary text in single quotation marks:
<
Such atoms can be (and are) treated as immutable strings in Prolog in many cases. Another string-like form wraps text in double quotation marks:
<
While this appears as a string to non-Prolog users, it is in reality a linked list of integers with each node containing the integer value of the character (or for Unicode-capable systems, code point) at that location. For example:
<
true.</
Individual character constants are special forms of integer (syntax sugar) using a 0' prefix:
<
true.</
{{works with|SWI Prolog|7.0}}
Line 2,052 ⟶ 2,225:
SWI-Prolog, beginning with version 7, introduced a new native string type. Unless options are specifically set by the user, character sequences wrapped in double quotes are now a string data type. The older list-based version uses back quotes instead:
<
false.
?- [97, 98, 99] = `abc`.
true.</
Also starting with SWI-Prolog version 7, quasiquotation became possible. While not exactly a string type directly, they can be (ab)used to give multi-line strings. More importantly, however, they permit special string handling to be embedded into Prolog code, in effect permitting entire other languages inside of Prolog to be used natively as per this example:
<
myodbc_connect_db(Conn),
odbc_query(Conn, {|odbc||
Line 2,071 ⟶ 2,244:
C.category_id=G.category_id
|}, Row),
writeln(Row).</
In this example, the test_qq_odbc/0 predicate connects to an ODBC database and performs a query. The query is wrapped into a multi-line quasiquotation (beginning with {| and ending with |}) that checks the syntax and security of the query, so not only is the query a multi-line string, it is a **checked** multiline string in this case.
Line 2,077 ⟶ 2,250:
=={{header|PureBasic}}==
PureBasic supports char in ASCII and UNICODE as well as both dynamic and fixed length strings.
<
Define.c AChar='A'
; defines as *.a it will be ASCII and *.u is always UNICODE
Line 2,092 ⟶ 2,265:
; '"' can be included via CHR() or its predefined constant
Define AStringQuotes$=Chr(34)+"Buu"+Chr(34)+" said the ghost!"
Define BStringQuotes$=#DOUBLEQUOTE$+"Buu"+#DOUBLEQUOTE$+" said yet a ghost!"</
To dynamically detect the current sizes of a character, e.g. ASCI or UNICODE mode, StringByteLength() can be used.
<
Case 1
Print("ASCII-mode; Soo, Hello world!")
Case 2
Print("UNICODE-mode; Soo, 您好世界!")
EndSelect</
=={{header|Python}}==
Line 2,106 ⟶ 2,279:
One can use single or double quotes.
<
'text' == "text"
' " '
Line 2,112 ⟶ 2,285:
'\x20' == ' '
u'unicode string'
u'\u05d0' # unicode literal</
As shown in the last examples, Unicode strings
Line 2,120 ⟶ 2,293:
This is useful when defining regular expressions as it avoids the need to use sequences like \\\\ (a sequence of four backslashes) in order to get one literal backslash into a regular expression string.
<
The Unicode and raw string modifiers can be combined to prefix a raw Unicode string. This '''must''' be done as "ur" or "UR" (not with the letters reversed as it: "ru").
Line 2,126 ⟶ 2,299:
Here-strings are denoted with triple quotes.
<
""" double triple quote """</
The "u" and "r" prefixes can also be used with triple quoted strings.
Line 2,162 ⟶ 2,335:
See [http://stat.ethz.ch/R-manual/R-patched/library/base/html/Quotes.html ?Quotes] for more information.
<
str2 <- 'the quick brown fox, etc.'
identical(str1, str2) #returns TRUE</
R also supports testing string literals with '''==''', e.g.,
<
mode.vec <- unlist(strsplit(modestring, ','))
mode.vec[1] # "row"
mode.vec[2] # "col"
if (mode.vec[2] == 'col') { cat('Col!\n') } # Col! (with no quotes)
if (mode.vec[1] == "row") { cat('Row!\n') } # Row!</
R also uses backticks, for creating non-standard variable names (amongst other things).
<
`a b` # 4
a b # Error: unexpected symbol in "a b"</
R will print different styles of single and double quote using sQuote and dQuote
<
cat("plain quotes: ", dQuote("double"), "and", sQuote("single"), "\n")</
returns
Line 2,190 ⟶ 2,363:
plain quotes: "double" and 'single'
<
cat("fancy quotes: ", dQuote("double"), "and", sQuote("single"), "\n")</
returns
Line 2,197 ⟶ 2,370:
fancy quotes: “double” and ‘single’
<
cat("fancy quotes: ", dQuote("double"), "and", sQuote("single"), "\n")</
returns
Line 2,209 ⟶ 2,382:
sometime using a name for the character.
<syntaxhighlight lang="racket">
#\a
#\space
#\return
</syntaxhighlight>
Strings are double-quoted, and have most of the usual C-style escapes.
Line 2,254 ⟶ 2,427:
In any case, an initial <tt>Q</tt>, <tt>q</tt>, or <tt>qq</tt> may omit the initial colon to form traditional Perl quotes such as <tt>qw//</tt>.
And Q can be used by itself to introduce a quote that has no escapes at all except for the closing delimiter:
<syntaxhighlight lang="raku"
Note that the single quotes there imply no single quoting semantics as they would in Perl 5. They're just the quotes the programmer happened to choose, since they were most like the raw quoting. Single quotes imply <tt>:q</tt> only when used as normal single quotes are, as discussed below.
As in Perl 5, you can use any non-alphanumeric, non-whitespace characters for delimiters with the general forms of quoting, including matching bracket characters, including any Unicode brackets.
Line 2,275 ⟶ 2,448:
Heredocs now have no special <tt><<</tt> syntax,
but fall out of the <tt>:to</tt> adverb:
<syntaxhighlight lang="raku"
Your ad here.
END</
Indentation equivalent to the ending tag is automatically removed.
Backslash sequences recognized by <tt>:b</tt> (and hence <tt>:qq</tt>) include:
<syntaxhighlight lang="raku"
"\b" # BACKSPACE
"\t" # TAB
Line 2,295 ⟶ 2,468:
"\c8" # BACKSPACE
"\c[13,10]" # CRLF
"\c[LATIN CAPITAL LETTER A, COMBINING RING ABOVE]"</
Leading <tt>0</tt> specifically does not mean octal in Perl 6;
you must use <tt>\o</tt> instead.
Line 2,304 ⟶ 2,477:
ASCII characters are prefixed by a single dollar sign.
<syntaxhighlight lang="retro">$c
'hello,_world!
'This_is_'a_string'
</syntaxhighlight>
=={{header|REXX}}==
Line 2,315 ⟶ 2,488:
There is no difference between them as far as specifying a REXX literal.
<br>You can double them (code two of them adjacent) to specify a quote within the string.
<
char2 = 'A'
str = "this is a string"
another = 'this is also a string'
escape1 = "that's it!"
escape2 = 'that''s it!'</
Variable expansion is not possible within REXX literals.
<br>Simply concatenate the string with the variable:
<
result = "You got" amount "points."
say result</
{{out}}
<pre>
Line 2,331 ⟶ 2,504:
</pre>
It's also possible to express characters in hexadecimal notation in a string:
<
cr = '0D'x
Line 2,337 ⟶ 2,510:
ppp = 'dead beaf 11112222 33334444 55556666 77778888 00009999 c0ffee'X
lang = '52455858'x /*which is "REXX" on ASCII-computers.*/</
Binary strings are also possible:
<
jjj = '01011011'b
jjj = "0101 1011"b
jjj = '0101 1011 1111'b
longjjj = '11110000 10100001 10110010 11100011 11100100'B</
=={{header|Ring}}==
<
see 'This is a "quoted string"'
</syntaxhighlight>
=={{header|Ruby}}==
Quotes that do not interpolate:
<
%q(not interpolating with (nested) parentheses
and newline)</
Quotes that interpolate:
<
"double quotes with \"embedded quote\"\nnewline and variable interpolation: #{a} % 10 = #{a % 10}"
%Q(same as above)
%|same as above|</
Heredocs
<
With an unquoted delimiter, this interpolates:
a = #{a}
Line 2,372 ⟶ 2,545:
print <<'NON_INTERPOLATING'
This will not interpolate: #{a}
NON_INTERPOLATING</
=={{header|Rust}}==
A <code>char</code> in Rust is a Unicode scalar value. A char type in Rust is always four bytes in size and can be denoted by single quotes:
<syntaxhighlight lang="rust">
let char01: char = 'a';
let char02: char = '\u{25A0}'; // Black square
let char03: char = '❤'; // Heart
</syntaxhighlight>
Rust has two common string types: <code>&str</code> and <code>String</code>. These different string types are used depending if it's a fixed string literal that is saved into the executable and lives throughout the program execution (usually borrowed as a <code>&str</code>), a string slice that references a contiguous sequence of elements (borrowed as a <code>&str</code>), or a <code>String</code> which allows for a growable heap allocated valid UTF-8 string. Only the <code>String</code> type is fully owned by its variable, and the other two are only interacted through the reference <code>&str</code>. The <code>&str</code> string slice type may point to a string literal or a heap-allocated string.
The String type in Rust is intended to always contain a valid UTF-8 string. UTF-8 is a "variable width" encoding, and therefore Strings are going to be typically smaller than an array of the same Rust <code>char</code>'s. For example, the String "hi" is all within ASCII, and therefore a UTF-8 String of "hi" represents each character as one byte each. On the other hand, a char array ['h', 'i'] would take up 8 bytes in total. A string is denoted by double quotes:
<syntaxhighlight lang="rust">
const string_literal_str1: &str = "Hi Rust!";
let string_slice_str1: &str = string_literal_str1; // Creating a string slice from a string literal
let string_slice_str2: &str = "hello str"; // String slice pointing to string literal "hello str"
let string1: String = String::new(); // Empty String
let string2: String = String::from("hello"); // Creating String from string literal "hello"
let string3: String = "hi".to_string();
let string4: String = "bye".to_owned();
let string5: String = "see you soon".into();
// The "to_string()", "to_owned" or "into" are all equivalent in the code above.
// The "to_string()", "to_owned" or "into" methods are needed so that a string slice (&str) or a string literal (&str) is explicitly converted into a heap-allocated fully-owned String type. Otherwise the compiler's type checker will complain "expected struct `String`, found `&str` (string slice)"
let string6: String = string_slice_str2.to_owned(); // Explictly converting the string_slice_str2 into a heap-allocated fully-owned String. This can be done with "to_string()", "to_owned" or "into".
// String slices can also point to heap allocated strings:
let string_slice_str3: &str = &string2; // Creating a string slice to a heap-allocated String.
let string7: String = string_slice_str3.to_string(); // Converting string_slice_str3 into a heap-allocated fully-owned String copy, resulting in a new independent owned string copy of the original String. This can be done with "to_string()", "to_owned" or "into".
</syntaxhighlight>
Rust supports verbatim strings and here-strings by putting <code>r#</code> before the first double quotes, and the end is marked by adding a <code>#</code> after the final double quotes. If there is a <code>"#</code> inside the contents of your here-string or your verbatim string then you can just add more <code>#</code>'s as required in both the beggining and the end:
<syntaxhighlight lang="rust">
let verbatim_here_string01: &str = r#"A \verbatim string\, line breaks in programming use \n and tabs \t"#;
let verbatim_here_string02: &str = r#"
A \multi-line\ string, in programming
line breaks use the characters \n
and for tabs we use the characters \t
"#;
let verbatim_here_string03: &str = r##"
Part number "#001": 1
Part number "#002": 2
Part number "#003": 3
"##;
</syntaxhighlight>
To expand variables in Rust we have 3 options: we can use the "format!" macro, the "print!" macro or the "println!" macro.
<syntaxhighlight lang="rust">
let number: i32 = 42;
let number_string: String = format!("Number: {}", number);
println!("The result in string form is '{}'.", number_string);
print!("The number is {}. ", number); // Print without line break
println!("Again, it's {}", number); // Print with line break
// The above prints:
// The result in string form is 'Number: 42'.
// The number is 42. Again, it's 42
</syntaxhighlight>
In Rust, there are other string types that are specialized to specific string requirements, such as working with system strings (OsString and OsStr), working with C strings (CString and CStr), and working with system paths (Path and PathBuf).
=={{header|S-lang}}==
Line 2,387 ⟶ 2,624:
* $ to request dollar prefix variable substitutions within the given string.
<
variable c, ch, s, b, r, v;
Line 2,433 ⟶ 2,670:
() = fputs(b, stdout);
() = fputs("\n", stdout);
printf("strlen(b) is %d, bstrlen(b) is %d\n", strlen(b), bstrlen(b));</
{{out}}
Line 2,479 ⟶ 2,716:
Character literals use single quotes marks:
<
However, symbols are denoted with a single quote,
so care must be taken not to confuse the two:
<
Strings can use either double quotes, or three successive double quotes.
The first allows special characters, the second doesn't:
<
res5: java.lang.String =
newline and slash:
Line 2,495 ⟶ 2,732:
scala> """newline and slash: \n and \\"""
res6: java.lang.String = newline and slash: \n and \\</
However, Unicode characters are expanded wherever they happen, even inside comments.
So, for instance:
<
uniquote: java.lang.String = normal string
scala> val insidequote = """an inside \u0022 quote"""
insidequote: java.lang.String = an inside " quote</
Finally, on version 2.7, the triple-double-quoted string ends at the third consecutive quote, on version 2.8 it ends on the last quote of a series of at least three double-quotes.
'''Scala 2.7'''
<
<console>:1: error: unterminated string
val error = """can't finish with a quote: """"
^</
'''Scala 2.8'''
<
success: java.lang.String = but it can on 2.8: "</
=={{header|Scheme}}==
Characters are specified using the "#\" syntax:
<
#\A
#\?
#\space
#\newline</
Strings are contained in double quotes:
<
Literal symbols, lists, pairs, etc. can be quoted using the quote syntax:
<
'(1 2 3) ; same as (list 1 2 3)
'() ; empty list
'(a . b) ; same as (cons 'a 'b)</
=={{header|Seed7}}==
Line 2,541 ⟶ 2,778:
A [http://seed7.sourceforge.net/manual/tokens.htm#Character_literals character literal] is written as UTF-8 encoded Unicode character enclosed in single quotes.
<
The type [http://seed7.sourceforge.net/manual/types.htm#string string] describes sequences of Unicode characters.
Line 2,547 ⟶ 2,784:
A [http://seed7.sourceforge.net/manual/tokens.htm#String_literals string literal] is a sequence of UTF-8 encoded Unicode characters surrounded by double quotes.
<
This means that 'z' and "z" are different.
Line 2,588 ⟶ 2,825:
Note that the integer literal is interpreted decimal unless it is written as [http://seed7.sourceforge.net/manual/types.htm#based_integer based integer].
<
There is also a possibility to break a string into several lines.
<
\ which continues in the next line\n\
\and contains a line break";</
There is no built-in mechanism for expanding variables within strings.
Line 2,600 ⟶ 2,837:
=={{header|Sidef}}==
Quotes that do not interpolate:
<
‚unicode single quoted’;
%q(not interpolating with (nested) parentheses
and newline);</
Quotes that interpolate:
<
"double \Uquotes\E with \"embedded quote\"\nnewline and variable interpolation: #{a} % 10 = #{a % 10}";
„same as above”;
%Q(same as above);</
Heredocs:
<
Implicit double-quoted (interpolates):
a = #{a}
Line 2,624 ⟶ 2,861:
print <<'NON_INTERPOLATING'
This will not interpolate: #{a}
NON_INTERPOLATING</
=={{header|Slate}}==
Line 2,630 ⟶ 2,867:
Characters are specified using the <tt>$</tt> syntax:
<
$D
$8
$,
$\s
$\n</
Strings are contained in single quotes, with backslash for escaping:
<
=={{header|SQL}}==
String literals in SQL use single-quotation. There are no escapes, but you can double a <tt>'</tt> mark to make a single <tt>'</tt> in the text.
<
=={{header|Standard ML}}==
Characters are contained in the <code>#""</code> syntax:
<
val it = #"a" : char</
Strings are contained in double quotes:
<
val it = "Hello world" : string</
Strings may be split across lines and concatenated
by having two backslashes around the newline and whitespace:
<
\def";
val it = "abcdef" : string</
=={{header|Swift}}==
<
let str1 = "\(you) can insert variables into strings."
let str2 = "Swift also supports unicode in strings ı∫ƒ∂ß´™¡à"
Line 2,667 ⟶ 2,904:
let str4 = "'" // '
let str5 = "\"" // "
println(str3)</
{{out}}
<pre>
Line 2,677 ⟶ 2,914:
Swift 4 introduced multi-line string literals called long strings. Long strings are strings delimited by <code>"""triple quotes"""</code> that can contain newlines and individual <code>"</code> characters without the need to escape them.
<
let xml == """
<?xml version="1.0"?>
Line 2,692 ⟶ 2,929:
"""
println(xml)</
{{out}}
<pre>
Line 2,715 ⟶ 2,952:
Double quotes allow command and variable interpolation:
<
puts $str ;# ==> This is Tcl 8.5 It is Mon Apr 06 16:49:46 EDT 2009</
Braces prevent interpolation
<
puts $str ;# ==> This is Tcl $::tcl_version\tIt is [clock format [clock seconds]]</
=={{header|TI-89 BASIC}}==
Line 2,731 ⟶ 2,968:
'''Basic strings''' are surrounded by quotation marks. Any Unicode character may be used except those that must be escaped: quotation mark, backslash, and the control characters other than tab (U+0000 to U+0008, U+000A to U+001F, U+007F).
<
'''Multi-line basic strings''' are surrounded by three quotation marks on each side and allow newlines. A newline immediately following the opening delimiter will be trimmed. All other whitespace and newline characters remain intact.
<
Roses are red
Violets are blue"""</
When the last non-whitespace character on a line is a <code>\</code> ("line ending backslash"), it will be trimmed along with all whitespace (including newlines) up to the next non-whitespace character or closing delimiter. All of the escape sequences that are valid for basic strings are also valid for multi-line basic strings.
<
str1 = "The quick brown fox jumps over the lazy dog."
Line 2,753 ⟶ 2,990:
fox jumps over \
the lazy dog.\
"""</
'''Literal strings''' are surrounded by single quotes and do not support escaping. This means that there is no way to write a single quote in a literal string. Like basic strings, they must appear on a single line.
<
winpath = 'C:\Users\nodejs\templates'
winpath2 = '\\ServerX\admin$\system32\'
quoted = 'Tom "Dubs" Preston-Werner'
regex = '<\i\c*\s*>'</
'''Multi-line literal strings''' are surrounded by three single quotes on each side and allow newlines. Like literal strings, there is no escaping whatsoever. A newline immediately following the opening delimiter will be trimmed. All other content between the delimiters is interpreted as-is without modification. One or two single quotes are allowed anywhere within a multi-line literal string, but sequences of three or more single quotes are not permitted.
<
lines = '''
The first newline is
Line 2,769 ⟶ 3,006:
All other whitespace
is preserved.
'''</
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT,{}
s1=*
Line 2,785 ⟶ 3,022:
show=JOIN(show)
PRINT show
</syntaxhighlight>
{{out}}
<pre>
Line 2,806 ⟶ 3,043:
enclosed with doublequotes and to put doublequote characters
in a string enclosed within singlequotes:
<
echo 'The girl said "hello" too.'</
We can also use an escapesequence to put doublequote characters in an interpolated string:
<
=== Here documents ===
Line 2,818 ⟶ 3,055:
Here documents cannot be used to represent literal strings as an expression for variable assignment.
<
1, High Street,
SMALLTOWN,
West Midlands.
WM4 5HD.
END</
=={{header|Ursala}}==
Single characters are denoted with a back quote.
<
Unprintable character constants can be expressed like this.
<
Strings are enclosed in single forward quotes.
<
A single quote in a string is escaped by another single quote.
<
Multi-line strings are enclosed in dash-brackets.
<syntaxhighlight lang="ursala">d =
-[this is a list
of strings]-</
Dash-bracket enclosed text can have arbitrary nested
unquoted expressions, provided they evaluate to lists
of character strings.
<
f = -[text -[ d ]- more -[ e ]- text ]-</
This notation can also be used for defining functions.
<
The double quotes aren't for character strings but
dummy variables.
Line 2,855 ⟶ 3,092:
A simple quoted string is of the form 'string'
e.g
<syntaxhighlight lang
=={{header|Vim Script}}==
Line 2,870 ⟶ 3,107:
{{works with|VBA|6.5}}
{{works with|VBA|7.1}}
<
Debug.Print "Tom said, 'The fox ran away.'"</
{{out}}
<pre>Tom said, "The fox ran away."
Line 2,880 ⟶ 3,117:
Visual Basic only supports single-line strings. The only escape sequence supported is the double double-quote (""), which is translated into a single double-quote.
<
Result: Tom said, "The fox ran away."</
=={{header|V (Vlang)}}==
Character literals for Unicode characters, "rune literals", are an alias for u32.
Character literals for UTF-8 characters, "string literals", are an alias for u8.
To denote rune, Unicode characters, ` (backticks) are used :
A rune can be converted to a UTF-8 string by using the .str() method.
rocket := `🚀`
rocket.str() == '🚀' // uses single quotes, not the backtick, after conversion
A string can be converted back to runes by the .runes() method.
hello := 'Hello World'
hello_runes := hello.runes() // [`H`, `e`, `l`, `l`, `o`, ` `, `W`, `o`, `r`, `l`, `d`]
In V, a string is an immutable array of read-only bytes. All Unicode characters are encoded using UTF-8:
mut s := 'hello 🌎'
s[0] = `H` // not allowed as immutable
// convert `string` to `[]u8`
s := 'hello 🌎'
arr := s.bytes()
assert arr.len == 10
// convert `[]u8` to `string`
s2 := arr.bytestr()
assert s2 == s
// indexing gives a byte, u8(66) == `B`
name := 'Bob'
println(name.len == 3) // will print 3
if name[0] == u8(66) {println(name[0].ascii_str())} // will print`B`
String literals are contained in quotes:
str:= "Hello, world!"
=={{header|WEB}}==
Line 2,934 ⟶ 3,223:
From v0.4.0 Wren also supports ''raw'' string literals. These are any text surrounded by triple double quotes, """, and are interpreted verbatim i.e. any control codes and/or interpolations are not processed as such. They can include single or double double quotes without problem.
<
var t = "abc\t123\%"
var u = "\U0001F64A\U0001F680"
Line 2,940 ⟶ 3,229:
var w = """a"bc""def\n%(v)"""
System.print([s, t, u, v, w])</
{{out}}
Line 2,951 ⟶ 3,240:
Xojo only supports single-line strings. The only escape sequence supported is the double double-quote (""), which is translated into a single double-quote.
<
Result: Tom said, "The fox ran away."</
=={{header|XPL0}}==
Line 3,006 ⟶ 3,295:
=={{header|XSLT}}==
XSLT is based on XML, and so can use either " or ' to delimit strings. Since XML attribute values are defined using double-quotes, one must use single-quotes for string literals within attributes.
<
Double and single quote characters may also be escaped with XML entities: &quot; and &apos; respectively.
=={{header|Z80 Assembly}}==
{{trans|6502 Assembly}}
Strings are enclosed in double quotes.
<syntaxhighlight lang="z80">db "Hello World"</syntaxhighlight>
Any typed character in double quotes is assembled as the ASCII equivalent of that character. Therefore the following two data blocks are equivalent:
<syntaxhighlight lang="z80">db "Hello World"
db $48,$65,$6c,$6c,$6f,$20,$57,$6f,$72,$6c,$64</syntaxhighlight>
The assembler typically assumes nothing with regard to special characters. A <code>\n</code> will be interpreted literally, for example. How special characters are handled depends on the printing routine of the hardware's BIOS, or one created by the programmer. If your printing routine is able to support a null terminator and ASCII control codes, the following represents "Hello World" with the new line command and null terminator:
<syntaxhighlight lang="z80">db "Hello World",13,10,0</syntaxhighlight>
Creating your own printing routine is a bit out of the scope of this task but here's a simple demonstration that supports the \n and null termination:
<syntaxhighlight lang="z80">PrintString:
; HL contains the pointer to the string literal.
ld a,(hl)
or a ;compares to zero quicker than "CP 0"
ret z ;we're done printing the string, so exit.
cp '\' ; a single ascii character is specified in single quotes. This compares A to the backslash's ASCII value.
jr z,HandleSpecialChars ; if accumulator = '\' then goto "HandleSpecialChars"
call PrintChar ;unimplemented print routine, depending on the system this is either a BIOS call
; or a routine written by the programmer.
inc hl ;next character
jr PrintString ;back to top
HandleSpecialChars:
inc hl ;next char
ld a,(hl)
cp 'n'
call z,NewLine ;unimplemented routine, advances text cursor to next line. Only called if accumulator = 'n'.
inc hl ;advance past the 'n' to the next char.
jr PrintString ;jump back to top. Notice that neither the backslash nor the character after it were actually printed.</syntaxhighlight>
=={{header|zkl}}==
Line 3,016 ⟶ 3,339:
here-strings:
<
0'|foo|
"bar\n";</
{{out}}
<pre>
"foobar\n"
</pre>
<
"foo = ",3,"\n"
"bar=",n,"\n"
);</
{{out}}
<pre>
|