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
78
votes
2 answers

How to append a character to a string in Golang?

How to append a character to a string in Go? This does not work: s := "hello"; c := 'x'; fmt.Println(s + c); invalid operation: s + c (mismatched types string and rune) This does not work either: s := "hello"; c := 'x'; fmt.Println(s +…
cohadar
  • 4,709
  • 2
  • 20
  • 21
76
votes
5 answers

How to concatenate two JSX fragment or variables or string and component (in Reactjs)?

I know JSX can be very misleading because it looks like strings and it is not, thus the "string" term in the question, even if we are not really manipulating strings. Here is a code example (wrong, obviously): let line =
Sephy
  • 50,022
  • 30
  • 123
  • 131
76
votes
12 answers

php String Concatenation, Performance

In languages like Java and C#, strings are immutable and it can be computationally expensive to build a string one character at a time. In said languages, there are library classes to reduce this cost such as C# System.Text.StringBuilder and Java…
Chris
  • 3,438
  • 5
  • 25
  • 27
75
votes
4 answers

How can multiple rows be concatenated into one in Oracle without creating a stored procedure?

How can I achieve the following in oracle without creating a stored procedure? Data Set: question_id element_id 1 7 1 8 2 9 3 10 3 11 3 12 Desired Result: question_id …
Dan Polites
  • 6,750
  • 10
  • 50
  • 56
74
votes
5 answers

Concatenate in bash the output of two commands without newline character

What I need: Suppose I have two commands, A and B, each of which returns a single-line string (i.e., a string with no newline character, except possibly 1 at the very end). I need a command (or sequence of piped commands) C that concatenates the…
synaptik
  • 8,971
  • 16
  • 71
  • 98
74
votes
1 answer

PHP variable interpolation vs concatenation

What is the difference between the two following methods (performance, readability, etc.) and what do you prefer? echo "Welcome {$name}s!" vs. echo "Welcome " . $name . "!";
Aley
  • 8,540
  • 7
  • 43
  • 56
74
votes
3 answers

How to force addition instead of concatenation in javascript

I'm trying to add all of the calorie contents in my javascript like this: $(function() { var data = []; $( "#draggable1" ).draggable(); $( "#draggable2" ).draggable(); $( "#draggable3" ).draggable(); …
Maureen Moore
  • 1,049
  • 2
  • 9
  • 21
73
votes
4 answers

Difference between concat and push?

Why does a return of the push method cause Uncaught TypeError: acc.push is not a function But a return concat results in the correct solution? [1, 2, 3, 4].reduce(function name(acc, curr) { if (even(curr)) { return acc.push(curr); } …
72
votes
17 answers

Merge (Concat) Multiple JSONObjects in Java

I am consuming some JSON from two different sources, I end up with two JSONObjects and I'd like to combine them into one. Data: "Object1": { "Stringkey":"StringVal", "ArrayKey": [Data0, Data1] } "Object2": { "Stringkey":"StringVal", …
DanInDC
  • 5,019
  • 8
  • 31
  • 25
71
votes
2 answers

Why does concatenation of DataFrames get exponentially slower?

I have a function which processes a DataFrame, largely to process data into buckets create a binary matrix of features in a particular column using pd.get_dummies(df[col]). To avoid processing all of my data using this function at once (which goes…
jfive
  • 1,291
  • 3
  • 14
  • 21
69
votes
10 answers

Python: Cut off the last word of a sentence?

What's the best way to slice the last word from a block of text? I can think of Split it to a list (by spaces) and removing the last item, then reconcatenating the list. Use a regular expression to replace the last word. I'm currently taking…
qwerty
  • 717
  • 1
  • 5
  • 5
68
votes
6 answers

How can I build/concatenate strings in JavaScript?

Does JavaScript support substitution/interpolation? Overview I'm working on a JavaScript project, and as it's getting bigger, keeping strings in good shape is getting a lot harder. I'm wondering what's the easiest and most conventional way to…
MrHaze
  • 3,786
  • 3
  • 26
  • 47
67
votes
10 answers

How can I do string concatenation, or string replacement in YAML?

I have this: user_dir: /home/user user_pics: /home/user/pics How could I use the user_dir for user_pics? If I have to specify other properties like this, it would not be very DRY.
Geo
  • 93,257
  • 117
  • 344
  • 520
67
votes
8 answers

How to concat two ArrayLists?

I have two ArrayLists of equal size. List 1 consists of 10 names and list 2 consists of their phone numbers. I want to concat the names and number into one ArrayList. How do I do this?
Anirudh
  • 2,767
  • 5
  • 69
  • 119
66
votes
4 answers

Aggregating by unique identifier and concatenating related values into a string

I have a need that I imagine could be satisfied by aggregate or reshape, but I can't quite figure out. I have a list of names (brand), and accompanying ID number (id). This data is in long form, so names can have multiple ID's. I'd like to…
roody
  • 2,633
  • 5
  • 38
  • 50