|
This article is about the string operation of computer programming. For other uses, see Concatenation (disambiguation).
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:
[edit] Different languagesDifferent languages use different operators. Most languages use the plus sign (" [edit] Examples
For a more detailed comparison, please see the concatenation comparison article. [edit] Programming conventions[edit] AssignmentMany languages, such as PHP and JavaScript have a variant of the assignment operator that allows concatenation and assignment to a variable in one statement. For example, in PHP and Perl: //Example 1 (concatenation operator ".") $var = "Hello " . "World"; //Example 2 (combined assignment and concatenation ".=") $var = "Hello "; $var .= "World"; Both examples produce the same result. [edit] InterpolationSome languages, (such as Perl, PHP, and most Unix shells), support variable interpolation as an alternative form of string concatenation. For example, in Perl, the concatenation syntax: my $stringVar; $stringVar = "World"; print "Hello " . $stringVar; can be substituted with the string literal syntax: my $stringVar; $stringVar = "World"; print "Hello $stringVar"; since double quoted string literals in Perl indicate scalar variables with the dollar sign ($) scalar sigil. [edit] See also[edit] External links
offerte voli | hoteles | precios | voli | die verzeichnis | annuarie web | stop smoking london |