Comparison of programming languages (strings)

From Wikipedia, the free encyclopedia
Jump to: navigation, search

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


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

Common variants[edit]

Operator Languages
+ ALGOL 68, BASIC, C++, C#, Cobra, Pascal, Object Pascal, Eiffel, Go, JavaScript, Java, Python, Turing, Ruby, Windows PowerShell, Objective-C, 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
.. Lua
, J programming language, Smalltalk
^ OCaml, Standard ML, F#, rc
// Fortran

Unique variants[edit]

  • Awk uses the empty string: two expressions adjacent to each other are concatenated. This is called juxtaposition. Unix shells have a similar syntax. Rexx uses this syntax for concatenation including an intervening space.
  • C allows juxtaposition for string literals, however, for strings stored as character arrays, the strcat function must be used.
  • COBOL uses the STRING statement to concatenate string variables.
  • MATLAB and Octave use the syntax "[x y]" to concatenate x and y.
  • Visual Basic Versions 1 to 6 can also use the "+" sign but, this leads to ambiguity if a string representing a number and a number is added together.
  • Microsoft Excel allows both "&" and the function "=CONCATENATE(X,Y)".

String literals[edit]

This section compares styles for declaring a string literal.

Quoted raw[edit]

"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,
`Hello, world!` D, Go, Smalltalk
R"(Hello, world!)" C++11

Quoted interpolated[edit]

"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!" 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)

Escaped quotes[edit]

"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, Python, JavaScript, Mathematica, 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[edit]

"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[edit]

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!")

{I said "Hello, world!"} REBOL

Here document[edit]

Syntax Language(s)
I have a lot of things to say
and so little time to say them
Bourne shell, Perl, PHP, Ruby
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
I have a lot of things to say
and so little time to say them

Unique quoting variants[edit]

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