Comparison of programming languages (strings)

del.icio.us del.icio.us
Digg Digg
Furl Furl
Reddit Reddit
Rojo Rojo
Add to OnlyWire
This article is part of the
Programming Language Comparison
series.
General Comparison
Basic Syntax
Basic Instructions
Arrays
Associative arrays
String Operations
String Functions
List comprehension
Object-oriented programming
Object-oriented constructors
Database access

Evaluation strategy
List of "hello world" programs

Comparison of ALGOL 68 and C++
Compatibility of C and C++
Comparison of Pascal and Borland Delphi
Comparison of Pascal and C
Comparison of Java and C++
Comparison of Java and C#
Comparison of C# and Visual Basic .NET
Comparison of ABAP and Java


Contents

Concatenation

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

Common variants

Operator Languages
+ BASIC, C++, C#, Pascal, Delphi, JavaScript, Java, Python,Turing, Ruby, Windows PowerShell
++ Haskell
$+ mIRC Scripting Language
& Ada, AppleScript, Curl, VHDL, Visual Basic, Excel
. 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
// Fortran

Unique variants

  • 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.
  • 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

This section compares styles for declaring a string literal.

Quoted raw

Syntax Language(s)
@"Hello, world!" C#
r"Hello, world!" Python
'Hello, world!' PHP, Perl, Windows PowerShell
<![CDATA[Hello, world!]]> XML (CDATA section)

Quoted interpolated

Syntax Language(s)
"Hello, $name!" PHP, Perl, Windows PowerShell
"Hello, #{name}!" Ruby


Escaped quotes

Syntax Language(s)
"I said \"Hello, world!\"" C, C++, C#, Java
"I said `"Hello, world!`"" Windows Powershell


Dual quoting

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

Multiple quoting

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


Here document

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

Unique quoting variants

Syntax Variant name Language(s)
"""Hello, world!""" Triple quoting Python
13HHello, world! Hollerith notation FORTRAN
(indented with whitespace) Indented with whitespace and newlines YAML

This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License.


Giant Panda

Mercedes Car
James Bond Guide
This site monitored by SitePinger.net