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
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
2380
votes
47 answers

How to concatenate text from multiple rows into a single text string in SQL Server

Consider a database table holding names, with three rows: Peter Paul Mary Is there an easy way to turn this into a single string of Peter, Paul, Mary?
JohnnyM
  • 28,758
  • 10
  • 38
  • 37
1171
votes
30 answers

Shortcuts in Objective-C to concatenate NSStrings

Are there any shortcuts to (stringByAppendingString:) string concatenation in Objective-C, or shortcuts for working with NSString in general? For example, I'd like to make: NSString *myString = @"This"; NSString *test = [myString…
typeoneerror
  • 55,990
  • 32
  • 132
  • 223
956
votes
19 answers

How to efficiently concatenate strings in go

In Go, a string is a primitive type, which means it is read-only, and every manipulation of it will create a new string. So if I want to concatenate strings many times without knowing the length of the resulting string, what's the best way to do…
Randy Sugianto 'Yuku'
  • 71,383
  • 57
  • 178
  • 228
912
votes
22 answers

How do I concatenate strings and variables in PowerShell?

Suppose I have the following snippet: $assoc = New-Object PSObject -Property @{ Id = 42 Name = "Slim Shady" Owner = "Eminem" } Write-Host $assoc.Id + " - " + $assoc.Name + " - " + $assoc.Owner I'd expect this snippet to show: 42…
Ninja Cowgirl
  • 10,421
  • 8
  • 33
  • 41
550
votes
9 answers

How do I concatenate strings?

How do I concatenate the following combinations of types: str and str String and str String and String
jsalter
  • 5,758
  • 2
  • 16
  • 10
542
votes
11 answers

How to concatenate strings in twig

Anyone knows how to concatenate strings in twig? I want to do something like: {{ concat('http://', app.request.host) }}
stoefln
  • 14,498
  • 18
  • 79
  • 138
482
votes
23 answers

How to use GROUP BY to concatenate strings in SQL Server?

How do I get: id Name Value 1 A 4 1 B 8 2 C 9 to id Column 1 A:4, B:8 2 C:9
Eldila
  • 15,426
  • 23
  • 58
  • 62
469
votes
12 answers

How can two strings be concatenated?

How can I concatenate (merge, combine) two values? For example I have: tmp = cbind("GAD", "AB") tmp # [,1] [,2] # [1,] "GAD" "AB" My goal is to concatenate the two values in "tmp" to one string: tmp_new = "GAD,AB" Which function can do this…
Hans
  • 5,345
  • 4
  • 18
  • 10
419
votes
16 answers

How to keep the spaces at the end and/or at the beginning of a String?

I have to concatenate these two strings from my resource/value files: you found ALL PAIRS ! on flips ! I do it this way : String…
Hubert
  • 16,012
  • 18
  • 45
  • 51
403
votes
17 answers

Using LINQ to concatenate strings

What is the most efficient way to write the old-school: StringBuilder sb = new StringBuilder(); if (strings.Count > 0) { foreach (string s in strings) { sb.Append(s + ", "); } sb.Remove(sb.Length - 2, 2); } return…
tags2k
  • 82,117
  • 31
  • 79
  • 106
401
votes
16 answers

String concatenation in Ruby

I am looking for a more elegant way of concatenating strings in Ruby. I have the following line: source = "#{ROOT_DIR}/" << project << "/App.config" Is there a nicer way of doing this? And for that matter what is the difference between << and +?
dagda1
  • 26,856
  • 59
  • 237
  • 450
292
votes
7 answers

How to set the id attribute of a HTML element dynamically with angularjs (1.x)?

Provided an HTML element of type div, how to set the value of its id attribute, which is the concatenation of a scope variable and a string ?
Th. Ma.
  • 9,432
  • 5
  • 31
  • 46
253
votes
10 answers

C++ equivalent of StringBuffer/StringBuilder?

Is there a C++ Standard Template Library class that provides efficient string concatenation functionality, similar to C#'s StringBuilder or Java's StringBuffer?
An̲̳̳drew
  • 13,375
  • 13
  • 47
  • 46
240
votes
3 answers

How to concatenate strings with padding in sqlite

I have three columns in an sqlite table: Column1 Column2 Column3 A 1 1 A 1 2 A 12 2 C 13 2 B 11 2 I need to select…
Akshara
  • 3,361
  • 9
  • 31
  • 29
1
2 3
99 100