Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Concatenation
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Joining of strings in a programming language}} {{Use dmy dates|date=June 2024}} {{About|the string operation of computer programming}} {{For|concatenation of general lists|Append}} {{More footnotes|date=June 2024}} {{ProgLangCompare}} {{Wikifunctions|Z10000|concat}} [[File:20241229 Using concatenate function in spreadsheet to create SVG code - demo.svg|thumb|upright=2| A spreadsheet's concatenate ("&") function is used to assemble a complex text string—in this example, [[XML]] code for an [[SVG]] "circle" element.]] In [[formal language|formal language theory]] and [[computer programming]], '''string concatenation''' is the operation of joining [[character string (computer science)|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]]s, string concatenation is a [[binary operation|binary]] [[infix operator]], and in some it is written without an operator. This is implemented in different ways: * [[operator overloading|Overloading]] the plus sign <code>+</code> Example from C#: <code>"Hello, " + "World"</code> has the value <code>"Hello, World"</code>. * Dedicated operator, such as <code>.</code> in PHP, <code>&</code> in Visual Basic<ref>{{cite web |url=http://msdn.microsoft.com/en-us/library/te2585xw.aspx |title=Concatenation Operators in Visual Basic |work=.NET Visual Basic guide Language features: Operators and expressions |date=2015 |publisher=Microsoft}}</ref>, and <code>||</code> in SQL.<ref>{{cite web |title=SQL {{!}} Concatenation Operator |url=https://www.geeksforgeeks.org/sql-concatenation-operator/ |website=geeksforgeeks.org |date=12 January 2018 |access-date=11 August 2023}}</ref><ref>{{cite web |url=http://docs.oracle.com/cd/B19306_01/server.102/b14200/operators003.htm |title=Concatenation Operator |work=Oracle Database Online Documentation, 10g Release 2 (10.2) / Administration: Database SQL Reference |publisher=Oracle}}</ref> This has the advantage over reusing <code>+</code> that it allows implicit [[type conversion]] to string. * [[string literal concatenation]], which means that adjacent strings are concatenated without any operator. Example from C: <code>"Hello, " "World"</code> has the value <code>"Hello, World"</code>. In many scientific publications or standards the concatenation operator notation used is <code>||</code>.<ref>{{Cite report |url=https://datatracker.ietf.org/doc/html/rfc8017#section-2 |title=PKCS #1: RSA Cryptography Specifications Version 2.2 |last=Moriarty |first=Kathleen |last2=Kaliski |first2=Burt |last3=Jonsson |first3=Jakob |last4=Rusch |first4=Aneas |date=November 2016|section=2. Notation |publisher=Internet Engineering Task Force |issue=RFC 8017}}</ref> ==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|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 ''S''<sub>1</sub> and ''S''<sub>2</sub>, the ''concatenation'' ''S''<sub>1</sub>''S''<sub>2</sub> consists of all strings of the form ''vw'' where ''v'' is a string from ''S''<sub>1</sub> and ''w'' is a string from ''S''<sub>2</sub>, or formally {{math|1=''S''<sub>1</sub>''S''<sub>2</sub> = {{mset| ''vw'' : ''v'' ∈ ''S''<sub>1</sub>, ''w'' ∈ ''S''<sub>2</sub> }}}}. Many authors also use concatenation of a string set and a single string, and vice versa, which are defined similarly by {{math|1=''S''<sub>1</sub>''w'' = {{mset| ''vw'' : ''v'' ∈ ''S''<sub>1</sub> }}}} and {{math|1=''vS''<sub>2</sub> = {{mset| ''vw'' : ''w'' ∈ ''S''<sub>2</sub> }}}}. In these definitions, the string ''vw'' is the ordinary concatenation of strings ''v'' and ''w'' as defined in the introductory section. For example, if {{math|1=''F'' = {{mset| a, b, c, d, e, f, g, h }}}}, and {{math|1=''R'' = {{mset| 1, 2, 3, 4, 5, 6, 7, 8 }}}}, then ''FR'' denotes the set of all [[chess board]] coordinates in [[algebraic notation (chess)|algebraic notation]], while e''R'' denotes the set of all coordinates of the kings' [[file (chess)|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]]). ==Algebraic properties== The strings over an alphabet, with the concatenation operation, form an [[associative property|associative]] algebraic structure called a [[free monoid]]. The [[identity element]] is the [[null string]]. Sets of strings with concatenation and [[Alternation (formal language theory)|alternation]] form a [[semiring]], with concatenation [[distributive property|distributing]] over alternation. The identity for alternation (the 0 element) is the [[empty set]] 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]] 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 [[radix|base]]. Examples include [[home prime]]s (primes obtained by repeatedly factoring the increasing concatenation of prime factors of a given number), [[Smarandache–Wellin number]]s (the concatenations of the first [[prime number]]s), and the [[Champernowne constant|Champernowne]] and [[Copeland–Erdős constant]]s (the real numbers formed by the decimal representations of the [[positive integers]] and the prime numbers, respectively). ==See also== * [[Rope (data structure)]] ==References== ===Citations=== {{reflist}} ===Sources=== * {{cite book |author1-link=John Hopcroft |first1=John E. |last1=Hopcroft |author2-link=Jeffrey Ullman |first2=Jeffrey D. |last2=Ullman |title=Introduction to Automata Theory, Languages and Computation |publisher=Addison-Wesley |year=1979 |isbn=0-201-02988-X }} * {{cite journal |author1-link=John Corcoran (logician) |last1=Corcoran |first1=John |last2=Frank |first2=William |last3=Maloney |first3=Michael |title=String theory |journal=Journal of Symbolic Logic |volume=39 |issue=4 |pages=625–637 |year=1974 |doi=10.2307/2272846 |jstor=2272846 |s2cid=2168826 |url=}} {{Authority control}} [[Category:Formal languages]] [[Category:Operators (programming)]] [[Category:String (computer science)]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:About
(
edit
)
Template:Authority control
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite report
(
edit
)
Template:Cite web
(
edit
)
Template:For
(
edit
)
Template:Math
(
edit
)
Template:More footnotes
(
edit
)
Template:ProgLangCompare
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Use dmy dates
(
edit
)
Template:Wikifunctions
(
edit
)