- 다른 뜻에 대해서는 array_merge() 문서를 참조하십시오.
- concat
- Concatenate
- operator + & . ~ ||
1 Overview[ | ]
- Definition: concatenate(string1,string2) returns string.
- Description: Concatenates (joins) two strings to each other, returning the combined string. Note that some languages like C have mutable strings, so really the second string is being appended to the first string and the mutated string is returned.
2 Bash[ | ]
Bash
Copy
str1="Hello,"
str2=" World"
output=$str1$str2
echo $output
# Hello, World
3 C[ | ]

C
Copy
#include <stdio.h>
#include <stdlib.h> // malloc
#include <string.h> // strlen
char* concat(const char *s1, const char *s2) {
char *res = malloc(strlen(s1) + strlen(s2) + 1);
strcpy(res, s1);
strcat(res, s2);
return res;
}
int main() {
char* str1 = "Hello,";
char* str2 = " World";
char* output = concat(str1, str2);
printf(output); // Hello, World
}
C
Copy
#include <stdio.h>
#include <stdlib.h> // malloc
#include <string.h> // strlen
char* concat(const char *s1, const char *s2) {
size_t len1 = strlen(s1);
size_t len2 = strlen(s2);
char *res = malloc(len1 + len2 + 1);
memcpy(res, s1, len1);
memcpy(res + len1, s2, len2 + 1);
return res;
}
int main() {
char* str1 = "Hello,";
char* str2 = " World";
char* output = concat(str1, str2);
printf(output); // Hello, World
}
4 C#[ | ]
C#
Copy
"abc" + "def"; // returns "abcdef"
5 Cmd[ | ]
Bash
Copy
set "str1=Hello,"
set "str2= World"
set "output=%str1%%str2%"
echo %output%
REM shows "Hello, World"
6 Excel[ | ]
PHP
Copy
="ab" & "cd" & "ef" // returns "abcdef"
PHP
Copy
=CONCATENATE("ab", "cd", "ef") // returns "abcdef"
7 Go[ | ]

Go
Copy
package main
import "fmt"
func main() {
s := "Hello"
s = s + "World"
fmt.Println(s) // HelloWorld
}
Loading
Go
Copy
package main
import "fmt"
func main() {
a := "Hello"
b := "World"
c := a + b
fmt.Println(c) // HelloWorld
}
Loading
8 Java[ | ]
Java
Copy
"abc" + "def" // returns "abcdef"
9 JavaScript[ | ]
JavaScript
Copy
console.log( "abc" + "def" ); // abcdef
▶ | abcdef |
JavaScript
Copy
var str1 = "abc";
var str2 = "def";
var output = str1.concat(str2);
console.log( output ); // abcdef
▶ | abcdef |
JavaScript
Copy
var str1 = "abc";
var str2 = "def";
var str3 = "ghi";
var output = str1.concat(str2,str3);
console.log( output ); // abcdefghi
▶ | abcdefghi |
10 Lua[ | ]

lua
Copy
print ( "abc" .. "def" )
-- abcdef
print ( "abc" .. "def" .. "ghi" )
-- abcdefghi
11 Lisp[ | ]
lisp
Copy
(concatenate 'string "abc " "def " "ghi") ; returns "abc def ghi"
12 Objective-C[ | ]
Objective-C
Copy
NSString* str = [@"abc" stringByAppendingString:@"def"];
NSLog(@"%@", str); // abcdef
Objective-C
Copy
NSString* str = [NSString stringWithFormat:@"%@%@%@", @"ab", @"cd", @"ef"];
NSLog(@"%@", str); // abcdef
Objective-C
Copy
+(NSString*)concat:(NSString*) str, ... {
NSString* arg;
va_list args;
va_start(args, str);
while((arg = va_arg(args, NSString*))) str = [str stringByAppendingString:arg];
va_end(args);
return str;
}
// NSString* str = [Util concat:@"ab", @"cd", @"ef", nil]; // abcdef
13 Pascal[ | ]
pascal
Copy
'abc' + 'def'; // returns "abcdef"
14 Perl[ | ]
Perl
Copy
'abc'.'def'; # returns "abcdef"
Perl
Copy
$str1 = 'abc';
$str2 = 'def';
print $str1.$str2; # abcdef
print "$str1$str2"; # abcdef
print "hello $str1 $str2"; # hello abc def
15 PHP[ | ]
PHP
Copy
'abc'.'def'; // returns "abcdef"
PHP
Copy
$str1 = 'abc';
$str2 = 'def';
echo $str1.$str2; // abcdef
echo "$str1$str2"; // abcdef
echo "hello $str1 $str2"; // hello abc def
16 PowerShell[ | ]
powershell
Copy
$a = 'hello'
$b = 'world'
$a + $b
echo $c
# helloworld
powershell
Copy
$a = 1
$b = 2
$a + $b
# 3
powershell
Copy
$a = 1
$b = 2
"" + $a + $b
# 12
powershell
Copy
$a = '1'
$b = '2'
$a + $b
# 12
17 Python[ | ]
Python
Copy
'abc' + 'def' # returns "abcdef"
18 R[ | ]

R
Copy
paste("abc","def",sep="")
## [1] "abcdef"
19 Ruby[ | ]
Ruby
Copy
puts 'abc' + 'def'
# abcdef
name = "Snoopy"
puts "My name is " + name
# My name is Snoopy
puts "My name is " << name
# My name is Snoopy
puts "My name is #{name}"
# My name is Snoopy
20 SQL[ | ]
20.1 MySQL[ | ]
sql
Copy
SELECT CONCAT('Hello','World');
-- HelloWorld
sql
Copy
SELECT CONCAT(col1, col2) FROM mytable;
UPDATE mytable SET col1 = CONCAT('Hello', col1) WHERE 1;
20.2 Oracle[ | ]
sql
Copy
SELECT col1 || '' || col2 FROM mytable;
20.3 MS SQL[ | ]
sql
Copy
SELECT col1 + '' + col2 FROM mytable;
20.4 PostgreSQL[ | ]
sql
Copy
SELECT col1 || '' || col2 FROM mytable;
21 VB[ | ]
vbnet
Copy
"abc" & "def" ' returns "abcdef"
"abc" + "def" ' returns "abcdef"
"abc" & Null ' returns "abc"
"abc" + Null ' returns Null