Questions tagged [string-concatenation]

String concatenation is the operation of joining two character strings end-to-end.

In particular in the theory of computation, the concatenation operation on strings is generalized to an operation on sets of strings as follows:

For two sets of strings S1 and S2, the concatenation S1S2 consists of all strings of the form vw where v is a string from S1 and w is a string from S2. In this definition, the string vw is the ordinary concatenation of strings v and w as defined in the introductory section. In this context, sets of strings are often referred to as formal languages.

Programming languages often provide operators (such as the + sign) to simplify concatenation of strings. For example, "s1" + "s2" would result in "s1s2".

2012 questions
32
votes
4 answers

Linq Aggregate complex types into a string

I've seen the simple example of the .net Aggregate function working like so: string[] words = { "one", "two", "three" }; var res = words.Aggregate((current, next) => current + ", " + next); Console.WriteLine(res); How could the 'Aggregate' function…
Myster
  • 17,704
  • 13
  • 64
  • 93
32
votes
7 answers

Is there an Oracle SQL query that aggregates multiple rows into one row?

I have a table that looks like this: A 1 A 2 B 1 B 2 And I want to produce a result set that looks like this: A 1 2 B 1 2 Is there a SQL statement that will do this? I am using Oracle. Related questions: Returning multiple rows from a single…
user128807
  • 10,447
  • 17
  • 53
  • 72
31
votes
2 answers

How to GROUP BY and CONCATENATE fields in redshift

How to GROUP BY and CONCATENATE fields in Redshift e.g. If I have table ID COMPANY_ID EMPLOYEE 1 1 Anna 2 1 Bill 3 2 Carol 4 2 Dave How can I get result like this COMPANY_ID EMPLOYEE 1 …
spats
  • 805
  • 1
  • 10
  • 12
30
votes
2 answers

How to concatenate static strings at compile time?

I am trying to use templates to create an analogue of the type_info::name() function which emits the const-qualified name. E.g. typeid(bool const).name() is "bool" but I want to see "bool const". So for generic types I define: template
George Skelton
  • 1,095
  • 1
  • 10
  • 22
30
votes
9 answers

Joining two strings with a comma and space between them

I have been given the two strings "str1" and "str2" and I need to join them into a single string. The result should be something like this: "String1, String 2". The "str1" and "str2" variables however do not have the ", ". So now for the question:…
Andrew P
  • 1,487
  • 5
  • 17
  • 18
30
votes
12 answers

Batch string concatenation in Excel

I have a couple hundred of cells in Excel I would like to concatenate into a single string. Is there a simpler method of doing this than going through them one by one manually in order to type them into CONCATENATE(A1, A2,…
Green Demon
  • 4,078
  • 6
  • 24
  • 32
29
votes
5 answers

Concatenating strings with `if` statements in JavaScript

I'm attempting to set up a script to concatenate some variables inside a string if they exist, in order to place the appropriate metadata tags into a rendered HTML document. My concatenation code is: data = "\n\n" + "\n\n\n"…
木川 炎星
  • 3,893
  • 13
  • 42
  • 51
28
votes
8 answers

Concatenation operator (+) vs. concat()

For string concatenation we can use either the concat() or concat operator (+). I have tried the following performance test and found concat() is faster and a memory efficient way for string concatenation. String concatenation comparison for 100,000…
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
28
votes
2 answers

String builder vs string concatenation

What is the benefit and trade-off of using a string builder over pure string concatenation? new StringBuilder(32).append(str1) .append(" test: ") .append(val) .append(" is changed") …
Chun ping Wang
  • 3,879
  • 12
  • 42
  • 53
27
votes
4 answers

Concatenating two text columns in dplyr

My data looks like this: round <- c(rep("A", 3), rep("B", 3)) experiment <- rep(c("V1", "V2", "V3"), 2) results <- rnorm(mean = 10, n = 6) df <- data.frame(round, experiment, results) > df round experiment results 1 A V1 …
mmyoung77
  • 1,343
  • 3
  • 14
  • 22
27
votes
2 answers

Concatenate char literal ('x') vs single char string literal ("x")

When I have a String that I need to concatenate a single char to its end, should I prefer s = .... + ']' over s = .... + "]" for any performance reason? I know array string joining and of String builders, and I am NOT asking for suggestions on how…
epeleg
  • 10,347
  • 17
  • 101
  • 151
27
votes
8 answers

MongoDB concatenate strings from two fields into a third field

How do I concatenate values from two string fields and put it into a third one? I've tried this: db.collection.update( { "_id": { $exists: true } }, { $set: { column_2: { $add: ['$column_4', '$column_3'] } } }, false, true ) which doesn't…
26
votes
5 answers

How to concatenate a String in EL?

How do I get the promoPrice variable to print as part of the string ONLY $4.67?

${(promoPrice != null) ? "ONLY $${promoPrice}" : "FREE"}

alquatoun
  • 580
  • 1
  • 5
  • 19
26
votes
6 answers

Python .join or string concatenation

I realise that if you have an iterable you should always use .join(iterable) instead of for x in y: str += x. But if there's only a fixed number of variables that aren't already in an iterable, is using .join() still the recommended way? For example…
Falmarri
  • 47,727
  • 41
  • 151
  • 191
25
votes
2 answers

Why am I getting a an error when creating a generated column in PostgreSQL?

CREATE TABLE my_app.person ( person_id smallserial NOT NULL, first_name character varying(50), last_name character varying(50), full_name character varying(100) generated always as (concat(first_name, ' ', last_name)) STORED, …