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
3478
votes
30 answers

How to concatenate string variables in Bash

In PHP, strings are concatenated together as follows: $foo = "Hello"; $foo .= " World"; Here, $foo becomes "Hello World". How is this accomplished in Bash?
Strawberry
  • 66,024
  • 56
  • 149
  • 197
3239
votes
31 answers

How do I concatenate two lists in Python?

How do I concatenate two lists in Python? Example: listone = [1, 2, 3] listtwo = [4, 5, 6] Expected outcome: >>> joinedlist [1, 2, 3, 4, 5, 6]
y2k
  • 65,388
  • 27
  • 61
  • 86
1572
votes
66 answers

How can I concatenate two arrays in Java?

I need to concatenate two String arrays in Java. void f(String[] first, String[] second) { String[] both = ??? } Which is the easiest way to do this?
Antti Kissaniemi
  • 18,944
  • 13
  • 54
  • 47
1471
votes
16 answers

Can I concatenate multiple MySQL rows into one field?

Using MySQL, I can do something like: SELECT hobbies FROM peoples_hobbies WHERE person_id = 5; My Output: shopping fishing coding but instead I just want 1 row, 1 col: Expected Output: shopping, fishing, coding The reason is that I'm selecting…
Dean Rather
  • 31,756
  • 15
  • 66
  • 72
1425
votes
20 answers

How to extend an existing JavaScript array with another array, without creating a new array

There doesn't seem to be a way to extend an existing JavaScript array with another array, i.e. to emulate Python's extend method. I want to achieve the following: >>> a = [1, 2] [1, 2] >>> b = [3, 4, 5] [3, 4, 5] >>> SOMETHING HERE >>> a [1, 2, 3,…
Dzinx
  • 55,586
  • 10
  • 60
  • 78
1127
votes
11 answers

How to concatenate (join) items in a list to a single string

How do I concatenate a list of strings into a single string? For example, given ['this', 'is', 'a', 'sentence'], how do I get "this-is-a-sentence"? For handling a few strings in separate variables, see How do I append one string to another in…
alvas
  • 115,346
  • 109
  • 446
  • 738
1104
votes
20 answers

StringBuilder vs String concatenation in toString() in Java

Given the 2 toString() implementations below, which one is preferred: public String toString(){ return "{a:"+ a + ", b:" + b + ", c: " + c +"}"; } or public String toString(){ StringBuilder sb = new StringBuilder(100); return…
non sequitor
  • 18,296
  • 9
  • 45
  • 64
969
votes
29 answers

Concatenating two std::vectors

How do I concatenate two std::vectors?
yigal
900
votes
8 answers

Pandas Merging 101

How can I perform a (INNER| (LEFT|RIGHT|FULL) OUTER) JOIN with pandas? How do I add NaNs for missing rows after a merge? How do I get rid of NaNs after merging? Can I merge on the index? How do I merge multiple DataFrames? Cross join with…
cs95
  • 379,657
  • 97
  • 704
  • 746
770
votes
25 answers

How to concatenate a std::string and an int

I thought this would be really simple, but it's presenting some difficulties. If I have std::string name = "John"; int age = 21; How do I combine them to get a single string "John21"?
Obediah Stane
  • 15,471
  • 14
  • 39
  • 28
751
votes
20 answers

Import multiple CSV files into pandas and concatenate into one DataFrame

I would like to read several CSV files from a directory into pandas and concatenate them into one big DataFrame. I have not been able to figure it out though. Here is what I have so far: import glob import pandas as pd # Get data file names path =…
jonas
  • 13,559
  • 22
  • 57
  • 75
708
votes
7 answers

How can I get the concatenation of two lists in Python without modifying either one?

In Python, the only way I can find to concatenate two lists is list.extend, which modifies the first list. Is there any concatenation function that returns its result without modifying its arguments?
Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159
651
votes
35 answers

Getting current date and time in JavaScript

I have a script that prints the current date and time in JavaScript, but the DATE is always wrong. Here is the code: var currentdate = new Date(); var datetime = "Last Sync: " + currentdate.getDay() + "/" + currentdate.getMonth() + "/" +…
Ricardo
  • 11,609
  • 8
  • 27
  • 39
585
votes
12 answers

String concatenation: concat() vs "+" operator

Assuming String a and b: a += b a = a.concat(b) Under the hood, are they the same thing? Here is concat decompiled as reference. I'd like to be able to decompile the + operator as well to see what that does. public String concat(String s) { …
shsteimer
  • 28,436
  • 30
  • 79
  • 95
471
votes
21 answers

Concatenate multiple files but include filename as section headers

I would like to concatenate a number of text files into one large file in terminal. I know I can do this using the cat command. However, I would like the filename of each file to precede the "data dump" for that file. Anyone know how to do…
Nick
  • 5,411
  • 4
  • 19
  • 7
1
2 3
99 100