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
241
votes
5 answers

String concatenation in MySQL

I am using MySQL and MySQL Workbench 5.2 CE. When I try to concatenate 2 columns, last_name and first_name, it doesn't work : select first_name + last_name as "Name" from test.student
Roshan
  • 2,604
  • 2
  • 15
  • 13
239
votes
7 answers

MySQL CONCAT returns NULL if any field contain NULL

I have following data in my table "devices" affiliate_name affiliate_location model ip os_type os_version cs1 inter Dell 10.125.103.25 Linux Fedora cs2 inter …
Neeraj
  • 8,625
  • 18
  • 60
  • 89
230
votes
12 answers

How do I concatenate text files in Python?

I have a list of 20 file names, like ['file1.txt', 'file2.txt', ...]. I want to write a Python script to concatenate these files into a new file. I could open each file by f = open(...), read line by line by calling f.readline(), and write each line…
JJ Beck
  • 5,193
  • 7
  • 32
  • 36
216
votes
9 answers

How to concatenate columns in a Postgres SELECT?

I have two string columns a and b in a table foo. select a, b from foo returns values a and b. However, concatenation of a and b does not work. I tried : select a || b from foo and select a||', '||b from foo Update from comments: both columns…
Alex
  • 7,007
  • 18
  • 69
  • 114
214
votes
6 answers

How do you concatenate Lists in C#?

If I have: List myList1; List myList2; myList1 = getMeAList(); // Checked myList1, it contains 4 strings myList2 = getMeAnotherList(); // Checked myList2, it contains 6 strings myList1.Concat(myList2); // Checked mylist1, it…
Matt
  • 5,249
  • 12
  • 40
  • 45
211
votes
21 answers

How do I concatenate strings in Swift?

How to concatenate string in Swift? In Objective-C we do like NSString *string = @"Swift"; NSString *resultStr = [string stringByAppendingString:@" is a new Programming Language"]; or NSString *resultStr=[NSString stringWithFormat:@"%@ is a new…
Rajneesh071
  • 30,846
  • 15
  • 61
  • 74
206
votes
14 answers

Android TextView : "Do not concatenate text displayed with setText"

I am setting text using setText() by following way. prodNameView.setText("" + name); prodOriginalPriceView.setText("" + String.format(getString(R.string.string_product_rate_with_ruppe_sign), "" + new BigDecimal(price).setScale(2,…
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
203
votes
13 answers

How do I combine two lists in Dart?

I was wondering if there was an easy way to concatenate two lists in dart to create a brand new list object. I couldn't find anything and something like this: My list: list1 = [1, 2, 3] list2 = [4, 5, 6] I tried: var newList = list1 + list2; I…
Alex
  • 2,033
  • 2
  • 11
  • 7
199
votes
7 answers

SQL UPDATE all values in a field with appended string CONCAT not working

Here is what I want to do: current table: +----+-------------+ | id | data | +----+-------------+ | 1 | max | | 2 | linda | | 3 | sam | | 4 | henry | +----+-------------+ Mystery Query (…
Fresheyeball
  • 29,567
  • 20
  • 102
  • 164
199
votes
6 answers

What is the best way to concatenate vectors in Rust?

Is it even possible to concatenate vectors in Rust? If so, is there an elegant way to do so? I have something like this: let mut a = vec![1, 2, 3]; let b = vec![4, 5, 6]; for val in &b { a.push(val); } Does anyone know of a better way?
Joe Thomas
  • 5,807
  • 6
  • 25
  • 36
198
votes
15 answers

Include constant in string without concatenating

Is there a way in PHP to include a constant in a string without concatenating? define('MY_CONSTANT', 42); echo "This is my constant: MY_CONSTANT";
Brian
  • 26,662
  • 52
  • 135
  • 170
198
votes
7 answers

Most efficient way to concatenate strings in JavaScript?

In JavaScript, I have a loop that has many iterations, and in each iteration, I am creating a huge string with many += operators. Is there a more efficient way to create a string? I was thinking about creating a dynamic array where I keep adding…
omega
  • 40,311
  • 81
  • 251
  • 474
188
votes
24 answers

How do I concatenate multiple C++ strings on one line?

C# has a syntax feature where you can concatenate many data types together on 1 line. string s = new String(); s += "Hello world, " + myInt + niceToSeeYouString; s += someChar1 + interestingDecimal + someChar2; What would be the equivalent in C++?…
Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
188
votes
5 answers

Concatenating null strings in Java

Why does the following work? I would expect a NullPointerException to be thrown. String s = null; s = s + "hello"; System.out.println(s); // prints "nullhello"
yavoh
  • 2,645
  • 5
  • 24
  • 21
178
votes
3 answers

How can I concatenate twice with the C preprocessor and expand a macro as in "arg ## _ ## MACRO"?

I am trying to write a program where the names of some functions are dependent on the value of a certain macro variable with a macro like this: #define VARIABLE 3 #define NAME(fun) fun ## _ ## VARIABLE int NAME(some_function)(int…
JJ.
  • 1,781
  • 2
  • 11
  • 3