HOME

TheInfoList



OR:

In
formal language theory In logic, mathematics, computer science, and linguistics, a formal language is a set of string (computer science), strings whose symbols are taken from a set called "#Definition, alphabet". The alphabet of a formal language consists of symbol ...
and
computer programming Computer programming or coding is the composition of sequences of instructions, called computer program, programs, that computers can follow to perform tasks. It involves designing and implementing algorithms, step-by-step specifications of proc ...
, string concatenation is the operation of joining character strings end-to-end. For example, the concatenation of "snow" and "ball" is "snowball". In certain formalizations of concatenation theory, also called string theory, string concatenation is a primitive notion.


Syntax

In many
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s, 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 many scientific publications or standards the concatenation operator notation used is , , .


Implementation

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, a potential run-time optimization.


Concatenation of sets of strings

In
formal language theory In logic, mathematics, computer science, and linguistics, a formal language is a set of string (computer science), strings whose symbols are taken from a set called "#Definition, alphabet". The alphabet of a formal language consists of symbol ...
and pattern matching (including
regular expressions A regular expression (shortened as regex or regexp), sometimes referred to as rational expression, is a sequence of character (computing), characters that specifies a pattern matching, match pattern in string (computer science), text. Usually ...
), the concatenation operation on strings is generalised to an operation on sets of strings as follows: For two sets of strings ''S''1 and ''S''2, the ''concatenation'' ''S''1''S''2 consists of all strings of the form ''vw'' where ''v'' is a string from ''S''1 and ''w'' is a string from ''S''2, or formally . Many authors also use concatenation of a string set and a single string, and vice versa, which are defined similarly by and . In these definitions, the string ''vw'' is the ordinary concatenation of strings ''v'' and ''w'' as defined in the introductory section. For example, if , and , then ''FR'' denotes the set of all chess board coordinates in algebraic notation, while e''R'' denotes the set of all coordinates of the kings' file. In this context, sets of strings are often referred to as formal languages. The concatenation operator is usually expressed as simple juxtaposition (as with
multiplication Multiplication is one of the four elementary mathematical operations of arithmetic, with the other ones being addition, subtraction, and division (mathematics), division. The result of a multiplication operation is called a ''Product (mathem ...
).


Algebraic properties

The strings over an alphabet, with the concatenation operation, form an associative algebraic structure called a free monoid. The
identity element In mathematics, an identity element or neutral element of a binary operation is an element that leaves unchanged every element when the operation is applied. For example, 0 is an identity element of the addition of real numbers. This concept is use ...
is the null string. Sets of strings with concatenation and alternation form a semiring, with concatenation distributing over alternation. The identity for alternation (the 0 element) is the
empty set In mathematics, the empty set or void set is the unique Set (mathematics), set having no Element (mathematics), elements; its size or cardinality (count of elements in a set) is 0, zero. Some axiomatic set theories ensure that the empty set exi ...
and identity for concatenation (the 1 element) is the set containing just the null string.


Applications


Audio and telephony

In programming for telephony, concatenation is used to provide dynamic audio feedback to a user. For example, in a "time of day" speaking clock, concatenation is used to give the correct time by playing the appropriate recordings concatenated together. For example: "at the tone, the time will be", "eight", "thirty", "five", "and", "twenty", "five", "seconds". The recordings themselves exist separately, but playing them one after the other provides a grammatically correct sentence to the listener. This technique is also used in number change announcements,
voice mail A voicemail system (also known as voice message or voice bank) is a computer-based system that allows callers to leave a Voice recording, recorded message when the recipient has been unable (or unwilling) to answer the Telephone, phone. Calls may ...
systems, or most telephony applications that provide dynamic feedback to the caller (e.g. moviefone, tellme, and others). Programming for any kind of computerised public address system can also employ concatenation for dynamic public announcements (for example, flights in an airport). The system would archive recorded speech of numbers, routes or airlines, destinations, times, etc. and play them back in a specific sequence to produce a grammatically correct sentence that is announced throughout the facility.


Database theory

One of the principles of relational database design is that the fields of data tables should reflect a single characteristic of the table's subject, which means that they should not contain concatenated strings. When concatenation is desired in a report, it should be provided at the time of running the report. For example, to display the physical address of a certain customer, the data might include building number, street name, building sub-unit number, city name, state/province name, postal code, and country name, e.g., "123 Fake St Apt 4, Boulder, CO 80302, USA", which combines seven fields. However, the customers data table should not use one field to store that concatenated string; rather, the concatenation of the seven fields should happen upon running the report. The reason for such principles is that without them, the entry and updating of large volumes of data becomes error-prone and labor-intensive. Separately entering the city, state, ZIP code, and nation allows data-entry validation (such as detecting an invalid state abbreviation). Then those separate items can be used for sorting or indexing the records, such as all with "Boulder" as the city name.


Recreational mathematics

In recreational mathematics, many problems concern the properties of numbers under concatenation of their numerals in some base. Examples include home primes (primes obtained by repeatedly factoring the increasing concatenation of prime factors of a given number), Smarandache–Wellin numbers (the concatenations of the first
prime number A prime number (or a prime) is a natural number greater than 1 that is not a Product (mathematics), product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime ...
s), and the Champernowne and Copeland–Erdős constants (the real numbers formed by the decimal representations of the
positive integers In mathematics, the natural numbers are the numbers 0, 1, 2, 3, and so on, possibly excluding 0. Some start counting with 0, defining the natural numbers as the non-negative integers , while others start with 1, defining them as the positiv ...
and the prime numbers, respectively).


See also

* Rope (data structure)


References


Citations


Sources

* * {{Authority control Formal languages Operators (programming) String (computer science)