Questions tagged [concatenation]

Joining of two or more sequences into a single sequence.

Concatenation refers to the joining of two or more elements into a single element.

In programming, this can refer to

  • concatenation, which joins multiple strings into a single string
  • concatenation, where one or more arrays are combined (mostly appended) to make a new array
  • specific concatenation functions that combine elements along a specified dimension (horizontally, or vertically for example), replicate and tile existing elements, and so forth.
12037 questions
448
votes
6 answers

How to use GROUP BY to concatenate strings in MySQL?

Basically the question is how to get from this: foo_id foo_name 1 A 1 B 2 C to this: foo_id foo_name 1 A B 2 C
Paweł Hajdan
  • 18,074
  • 9
  • 49
  • 65
430
votes
12 answers

Which is the preferred way to concatenate a string in Python?

Since Python's string can't be changed, I was wondering how to concatenate a string more efficiently? I can write like it: s += stringfromelsewhere or like this: s = [] s.append(somestring) # later s = ''.join(s) While writing this…
Max
  • 7,957
  • 10
  • 33
  • 39
424
votes
17 answers

How do I concatenate const/literal strings in C?

I'm working in C, and I have to concatenate a few things. Right now I have this: message = strcat("TEXT ", var); message2 = strcat(strcat("TEXT ", foo), strcat(" TEXT ", bar)); Now if you have experience in C I'm sure you realize that this gives…
The.Anti.9
  • 43,474
  • 48
  • 123
  • 161
416
votes
14 answers

Why is [1,2] + [3,4] = "1,23,4" in JavaScript?

I wanted to add the elements of an array into another, so I tried this: [1,2] + [3,4] It responded with: "1,23,4" What is going on?
okeen
  • 3,976
  • 2
  • 15
  • 19
400
votes
4 answers

Scala list concatenation, ::: vs ++

Is there any difference between ::: and ++ for concatenating lists in Scala? scala> List(1,2,3) ++ List(4,5) res0: List[Int] = List(1, 2, 3, 4, 5) scala> List(1,2,3) ::: List(4,5) res1: List[Int] = List(1, 2, 3, 4, 5) scala> res0 == res1 res2:…
Luigi Plinge
  • 50,650
  • 20
  • 113
  • 180
399
votes
7 answers

Concatenating two one-dimensional NumPy arrays

How do I concatenate two one-dimensional arrays in NumPy? I tried numpy.concatenate: import numpy as np a = np.array([1, 2, 3]) b = np.array([4, 5]) np.concatenate(a, b) But I get an error: TypeError: only length-1 arrays can be converted to…
highBandWidth
  • 16,751
  • 20
  • 84
  • 131
394
votes
9 answers

Python strings and integer concatenation

I want to create a string using an integer appended to it, in a for loop. Like this: for i in range(1, 11): string = "string" + i But it returns an error: TypeError: unsupported operand type(s) for +: 'int' and 'str' What's the best way to…
michele
  • 26,348
  • 30
  • 111
  • 168
357
votes
5 answers

How to concatenate two dictionaries to create a new one?

Say I have three dicts d1={1:2,3:4} d2={5:6,7:9} d3={10:8,13:22} How do I create a new d4 that combines these three dictionaries? i.e.: d4={1:2,3:4,5:6,7:9,10:8,13:22}
timy
  • 3,663
  • 4
  • 18
  • 8
343
votes
16 answers

Is it better practice to use String.format over string Concatenation in Java?

Is there a perceptible difference between using String.format and String concatenation in Java? I tend to use String.format but occasionally will slip and use a concatenation. I was wondering if one was better than the other. The way I see it,…
Omar Kooheji
  • 54,530
  • 68
  • 182
  • 238
315
votes
7 answers

Merge two dataframes by index

I have the following dataframes: > df1 id begin conditional confidence discoveryTechnique 0 278 56 false 0.0 1 1 421 18 false 0.0 1 > df2 concept 0 A 1 B How do I…
brucezepplin
  • 9,202
  • 26
  • 76
  • 129
302
votes
13 answers

Easy way to concatenate two byte arrays

What is the easy way to concatenate two byte arrays? Say, byte a[]; byte b[]; How do I concatenate two byte arrays and store it in another byte array?
androidGuy
  • 5,553
  • 12
  • 39
  • 56
296
votes
16 answers

PHP - concatenate or directly insert variables in string

I am wondering, What is the proper way for inserting PHP variables into a string? This way: echo "Welcome ".$name."!" Or this way: echo "Welcome $name!" Both of these methods work in my PHP v5.3.5. The latter is shorter and simpler but I'm not…
Web_Designer
  • 72,308
  • 93
  • 206
  • 262
276
votes
6 answers

How to concatenate two IEnumerable into a new IEnumerable?

I have two instances of IEnumerable (with the same T). I want a new instance of IEnumerable which is the concatenation of both. Is there a built-in method in .NET to do that or do I have to write it myself?
Samuel Rossille
  • 18,940
  • 18
  • 62
  • 90
271
votes
5 answers

What does ${} (dollar sign and curly braces) mean in a string in JavaScript?

I haven't seen anything here or on MDN. I'm sure I'm just missing something. There's got to be some documentation on this somewhere. Functionally, it looks like it allows you to nest a variable inside a string without doing concatenation using the +…
Darren Joy
  • 2,849
  • 2
  • 12
  • 10
271
votes
6 answers

Concatenate a list of pandas dataframes together

I have a list of Pandas dataframes that I would like to combine into one Pandas dataframe. I am using Python 2.7.10 and Pandas 0.16.2 I created the list of dataframes from: import pandas as pd dfs = [] sqlall = "select * from mytable" for chunk in…
Whitebeard
  • 5,945
  • 5
  • 24
  • 31