Comparison of programming languages (strings)

From Wikipedia, the free encyclopedia

This article is part of the
Programming Language Comparison
series.
General Comparison
Basic Syntax
Basic Instructions
Arrays
Associative arrays
String Operations
String Functions
Object-oriented programming
Database access

Evaluation strategy
List of "hello world" programs

Comparison of ALGOL 68 and C++
Compatibility of C and C++
Comparison of C and Pascal
Comparison of C++ and Java
Comparison of C# and Java
Comparison of C# and Visual Basic .NET
Comparison of ABAP and Java
This box: view  talk  edit


Contents

[edit] Concatenation

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

[edit] Common variants

   +       ;; BASIC, C++, C#, Pascal, Delphi, JavaScript, Java, Python,
              Turing, Ruby, Windows PowerShell
   ++      ;; Haskell
   &       ;; Ada, AppleScript, Curl, VHDL, Visual Basic,  Excel
   .       ;; Perl (before version 6), PHP, and Maple (up to version 5)
   ~       ;; Perl 6 and D 
   ||      ;; Icon, Standard SQL, PL/I, Rexx, and Maple (from version 6)
   <>      ;; Mathematica 
   ..      ;; Lua
   ,       ;; J programming language
   ^       ;; OCaml and Standard ML
   //      ;; Fortran

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

[edit] String literals

This section compares styles for declaring a string literal.

[edit] Quoted raw

@"TheQuickBrownFox"              ;; C#
r"TheQuickBrownFox"              ;; Python
'TheQuickBrownFox'               ;; Perl, Windows PowerShell
<![CDATA[ TheQuickBrownFox ]]>   ;; XML (CDATA section)

[edit] Quoted interpolated


[edit] Dual quoting


[edit] Multiple quoting


[edit] Unique quoting variants

   16HTheQuickBrownFox          ;; Hollerith notation                    ;; FORTRAN
   (indented with whitespace)   ;; Indented with whitespace and newlines ;; YAML