- For concatenation of general lists, see append.
In computer programming
, string concatenation
is the operation of joining two character strings
end to end. For example, the strings "foo" and "bar" may be concatenated to give "foobar
". In many programming languages
, string concatenation is a binary infix operator
For example, the following expression uses the "+" symbol as the concatenation operator:
print "Hello " + "World";
Different languages use different operators. Most languages use the plus sign ("+") though several deviate from this norm.
|| Symbol name
|| Language |
|| plus sign
|| Ada, AppleScript, VHDL, Visual Basic |
|| Perl (before version 6), PHP |
|| Perl 6 |
||double slash|| Fortran |
|| double vertical bar
|| REXX, SQL, Icon |
|| dollar plus
|| mIRC Scripting Language |
For a more detailed comparison, please see the concatenation comparison article.
Many languages, such as PHP
have a variant of the assignment operator
that allows concatenation and assignment to a variable in one statement.
For example, in PHP and Perl:
Both examples produce the same result.
Some languages, (such as Perl
, and most Unix shells
), support variable interpolation
as an alternative form
of string concatenation.
For example, in Perl, the concatenation syntax:
can be substituted with the string literal syntax:
since double quoted string literals in Perl indicate scalar variables with
the dollar sign ($) scalar sigil.