Comparison of programming languages (strings)

This comparison of programming languages (strings) compares the features of string data structures or text-string processing for over 52 various computer programming languages.

Concatenation

Different languages use different symbols for the concatenation operator. Many languages use the "+" symbol, though several deviate from this.

Common variants

Operator Languages
+ ALGOL 68, BASIC, C++, C#, Cobra, Pascal, Object Pascal, Eiffel, Go, JavaScript, Java, Python, Turing, Ruby, Windows PowerShell, Objective-C, Swift, F#, Scala, Ya
++ Haskell, Erlang
$+ mIRC Scripting Language
& Ada, AppleScript, COBOL (for literals only), Curl, Seed7, VHDL, Visual Basic, Excel, FreeBASIC
nconc Common Lisp
. Perl (before version 6), PHP, and Maple (up to version 5), Autohotkey
~ Perl 6 and D
|| Icon, Standard SQL, PL/I, Rexx, and Maple (from version 6)
<> Mathematica, Wolfram Language
.. Lua
, J programming language, Smalltalk
^ OCaml, Standard ML, F#, rc
// Fortran

Unique variants

String literals

This section compares styles for declaring a string literal.

Quoted raw

"Raw" meaning that the interpreter/compiler does not recognize any variable or constant identifiers located inside the string and the content of the identifier will not replace the identifier in the string.

Syntax Language(s)
@"Hello, world!" C#, F#
"Hello, world!" Cobol, FreeBASIC, Java, JavaScript
r"Hello, world!" D, Python, Cobra
'Hello, world!' Fortran, JavaScript, Object Pascal, Pascal, Perl, PHP, Windows PowerShell, Smalltalk
`Hello, world!` D, Go
R"(Hello, world!)" C++11

Quoted interpolated

"Interpolated" means that the interpreter/compiler does recognize a variable or constant identifier located inside the string and the content of the identifier will replace the identifier in the string.

Syntax Language(s)
$"hello, {name}" C#
"Hello, $name!" PHP, Perl, Windows PowerShell, Bash shell
"Hello, {$name}!" PHP
"Hello, #{name}!" Ruby, CoffeeScript
(format t "Hello, ~A" name) Common Lisp
`Hello, ${name}!` JavaScript (ECMAScript 6)
"Hello, \(name)!" Swift

Escaped quotes

"Escaped" quotes means that a 'flag' symbol is used to warn that the character after the flag is used in the string rather than ending the string.

Syntax Language(s)
"I said \"Hello, world!\"" C, C++, C#, D, F#, Java, Ocaml, Perl, PHP, Python, Swift, JavaScript, Mathematica, Wolfram Language, Ya
'I said ''Hello, world!''' Smalltalk
"I said `"Hello, world!`"" Windows Powershell
"I said ^"Hello, world!^"" REBOL
"I said, %"Hello, World!%"" Eiffel
!"I said \"Hello, world!\"" FreeBASIC

Dual quoting

"Dual quoting" means that whenever a quote is used in a string, it is used twice, and one of them is discarded and the single quote is then used within the string.

Syntax Language(s)
"I said ""Hello, world!""" Ada, ALGOL 68, Excel, Fortran, Visual Basic, FreeBASIC, COBOL
'I said ''Hello, world!''' Fortran, rc, COBOL, SQL, Pascal, Object Pascal
'I said "Hello, world!"' Smalltalk

Multiple quoting

Syntax Language(s)
q(I said "Hello, world!")

qq(I said "Hello, $name!")

Perl (raw & interpolated)
%Q(I said "Hello, world!")

%(I said "Hello, world!")

Ruby
{I said "Hello, world!"} REBOL

Here document

Syntax Language(s)
<<EOF
I have a lot of things to say
and so little time to say them
EOF
Bourne shell, Perl, PHP, Ruby
<<<EOF
I have a lot of things to say
and so little time to say them
EOF
PHP
@"
I have a lot of things to say
and so little time to say them
"@
Windows Powershell
"[
I have a lot of things to say
and so little time to say them
]"
Eiffel
"""
I have a lot of things to say
and so little time to say them
"""
CoffeeScript

Unique quoting variants

Syntax Variant name Language(s)
"""Hello, world!""" Triple quoting Python
13HHello, world! Hollerith notation Fortran 66
(indented with whitespace) Indented with whitespace and newlines YAML
This article is issued from Wikipedia - version of the 11/28/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.