In formal language theory and computer programming, string concatenation is the operation of joining character strings end-to-end. For example, the concatenation of "snow" and "ball" is "snowball". In certain formalisations of concatenation theory, also called string theory, string concatenation is a primitive notion.
In many programming languages, string concatenation is a binary infix operator, and in some it is written without an operator. This is implemented in different ways:
Overloading the plus sign + Example from C#: "Hello, " + "World" has the value "Hello, World".
Dedicated operator, such as . in PHP, & in Visual Basic and || in SQL. This has the advantage over reusing + that it allows implicit type conversion to string.
string literal concatenation, which means that adjacent strings are concatenated without any operator. Example from C: "Hello, " "World" has the value "Hello, World".
In programming, string concatenation generally occurs at run time, as string values are typically not known until run time. However, in the case of string literals, the values are known at compile time, and thus string concatenation can be done at compile time, either via string literal concatenation or via constant folding.
In formal language theory and pattern matching (including regular expressions), the concatenation operation on strings is generalised to an operation on sets of strings as follows:
For two sets of strings S1 and S2, the concatenation S1S2 consists of all strings of the form vw where v is a string from S1 and w is a string from S2, or formally S1S2 = . Many authors also use concatenation of a string set and a single string, and vice versa, which are defined similarly by S1w = and vS2 = . In these definitions, the string vw is the ordinary concatenation of strings v and w as defined in the introductory section.
For example, if F = , and R = , then FR denotes the set of all chess board coordinates in algebraic notation, while eR denotes the set of all coordinates of the kings' .