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

Warning in StringBuffer and StringBuilder

I have a StringBuffer initialized outside for loop and inside for loop I am concatenating some strings. I am getting the warning 'StringBuffer stringBuffer' may be declared as 'StringBuilder' and string concatenation as argument to…
Abish R
  • 1,537
  • 3
  • 18
  • 36
25
votes
4 answers

MongoDB Aggregation join array of strings to single string

We're trying to 'join' an array of strings to a single string within an aggregation. Given is the following dataset: Collection 1: { id: 1234, field: 'test' } Collection 2: { id: 1111, collection1_id: 1234, name: 'Max' }, { id: 1112, …
patrickkeller
  • 1,236
  • 2
  • 11
  • 20
25
votes
1 answer

SQLite Update Syntax for string concatenation?

I have a table with this data id , name , description 1 , apple , '' 2 , orange , '' I am trying to pass the following statement to update the row so the description column is 'desc of apple' and 'desc of orange' but it is not working. …
Snowy
  • 5,942
  • 19
  • 65
  • 119
25
votes
3 answers

Does concatenating strings in Java always lead to new strings being created in memory?

I have a long string that doesn't fit the width of the screen. For eg. String longString = "This string is very long. It does not fit the width of the screen. So you have to scroll horizontally to read the whole string. This is very inconvenient…
CodeBlue
  • 14,631
  • 33
  • 94
  • 132
23
votes
2 answers

Difference between c++ string append and operator +=

Is there any noticeable difference between the two lines? My coworker says that using += is "faster" but I don't see why they should be any different: string s1 = "hello"; string s2 = " world"; // Option 1 s1 += s2; // Option 2 s1.append(s2); To…
ClydeTheGhost
  • 1,473
  • 2
  • 17
  • 31
23
votes
5 answers

C++ String Concatenation operator<<

I have realised my mistake. I was trying to concatenate two strings. I have just started to learn C++. I have a problem about string concatenation. I don't have problem when I use: cout << "Your name is"<
backspace
  • 299
  • 2
  • 3
  • 7
23
votes
1 answer

How to store a string var greater than varchar(max)?

I'm trying to do this: DECLARE @myVar VARCHAR(MAX) Loop with cursor select @myVar = @myVar + bla bla bla end loop When the loop ends, @myVar is incomplete, containing only 8000 characters. I have tryed to use text, but is not allowed to local…
Eduardo
  • 693
  • 3
  • 9
  • 21
22
votes
1 answer

How to concatenate Strings in EL expression?

I need to create a callback for while as a parameter I need to pass an argument that is string-concatenated with an external parameter id: I tried nesting an EL expression something like this:
Benjamin Harel
  • 2,906
  • 3
  • 24
  • 32
22
votes
3 answers

How can I concatenate forloop.counter to a string in my django template

I am already trying to concatenate like this: {% for choice in choice_dict %} {% if choice =='2' %} {% with "mod"|add:forloop.counter|add:".html" as template %} {% include template %} {% endwith %} …
Ethan
  • 251
  • 1
  • 2
  • 8
22
votes
7 answers

XPath to return string concatenation of qualifying child node values

Can anyone please suggest an XPath expression format that returns a string value containing the concatenated values of certain qualifying child nodes of an element, but ignoring others:
This text node should be returned. And the…
Tim Coulter
  • 8,705
  • 11
  • 64
  • 95
22
votes
4 answers

How to Concatenate String in Objective-C (iPhone)?

Possible Duplicate: How do I concatenate strings in Objective-C? Firstly, the platform is iPhone and label.text changes the label displayed. Consider this scenario: I've an array of integers. And I want to display it on the screen. Here's my…
r0ach
  • 511
  • 3
  • 6
  • 14
21
votes
4 answers

String concatenation in EL for dynamic ResourceBundle key

I have a resource bundle with entries like these: entry1=value1 entry2=value2 entry3=value3 In my JSF page I'm trying to use these keys dynamically. The ID of the entry is coming from a managed bean. I think it should be something like…
21
votes
3 answers

String concatenation operator in Oracle, Postgres and SQL Server

Is there a way to have a common operator for concatenation in Oracle, Postgres and SQL Server. In Oracle and Postgres we use || and SQL Server uses +. I've solved the problem in Postgres by adding the custom operator + to support string…
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
21
votes
3 answers

C string concatenation of constants

One of the answers to Why do you not use C for your web apps? contains the following: For the C crap example below: const char* foo = "foo"; const char* bar = "bar"; char* foobar = (char*)malloc(strlen(foo)+strlen(bar)+1); strcpy(foobar,…
Frank Vilea
  • 8,323
  • 20
  • 65
  • 86
20
votes
2 answers

String.Format vs "string" + "string" or StringBuilder?

Possible Duplicates: Is String.Format as efficient as StringBuilder C# String output: format or concat? What is the performance priority and what should be the conditions to prefer each of the following: String.Format("{0}, {1}", city,…