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
14
votes
4 answers

Using character instead of String for single-character values in StringBuffer append

I was going through the PMD rule AppendCharacterWithChar. It says Avoid concatenating characters as strings in StringBuffer.append. StringBuffer sb = new StringBuffer(); // Avoid this sb.append("a"); // use instead something like this …
Zeeshan
  • 11,851
  • 21
  • 73
  • 98
14
votes
3 answers

Why doesn't join() automatically convert its arguments to strings? When would you ever not want them to be strings?

We have a list: myList = [1, "two"] And want to print it out, normally I would use something like: "{0} and {1}".format(*myList) But you could also do: " and ".join(myList) But unfortunately: >>> " and ".join(myList) Traceback (most recent call…
LittleBobbyTables
  • 4,361
  • 9
  • 38
  • 67
14
votes
1 answer

Concatenate many rows into a single text string with grouping

I have the following table: tblFile My Desired output: I am Concatenating many rows into a single text string; however, I cannot get the grouping correct. As the code is now it will just display for each record in the FileNameString field:…
user1783736
  • 239
  • 2
  • 7
  • 13
14
votes
4 answers

ASP.Net MVC 3 Razor Concatenate String

I have the following in my ASP.Net MVC 3 Razor View @foreach (var item in Model.FormNotes) { @Html.DisplayFor(modelItem => item.User.firstName) } Which works fine, however, I would like to concatenate the…
tcode
  • 5,055
  • 19
  • 65
  • 124
13
votes
2 answers

Evaluate preprocessor token before ## concatenation

I would like to evaluate a token before it is concatenated with something else. The "problem" is that the standard specifies the behaviour as before the replacement list is reexamined for more macro names to replace, each instance of a ##…
hlovdal
  • 26,565
  • 10
  • 94
  • 165
13
votes
1 answer

How to do string concatenation in Scala

I have the following code that based on the input (args) I want to create a string but the answer is incorrect. I have args(0) is a path, args(1) is an operand like "+", and args(2) is a number (and I want to put space between them: //some code .. …
Mahsa
  • 1,502
  • 7
  • 18
  • 40
13
votes
7 answers

Why is 'join' faster than normal concatenation?

I've seen several examples from different languages that unambiguously prove that joining elements of a list (array) is many times faster than just concatenating string. Why? What is the inner algorithm that works under both operations and why is…
Ilian Iliev
  • 3,217
  • 4
  • 26
  • 51
13
votes
3 answers

How to Concat String in SQL WHERE clause

I have declared two variables in RAW sql DECLARE @str nvarchar(max), @str1 nvarchar (max); SET @str = " AND (c.BondSales_Confirmed <> -1)"; SET @str1 = " AND (c.BondSales_IssueType = 'REGULAR')"; My SQL query is: SELECT * From t_BondSales Where…
13
votes
6 answers

String.Join performance issue in C#

I've been researching a question that was presented to me: How to write a function that takes a string as input and returns a string with spaces between the characters. The function is to be written to optimize performance when it is called…
Vivian River
  • 31,198
  • 62
  • 198
  • 313
12
votes
1 answer

Escaping double quote in Common Lisp

How to escape double quotes while concatenating a string? For example i hoped (concatenate 'string "Mama said: " "\"Son, your life is an open book...\"") to give: "Mama said: "Son, your life is an open book..."" but instead returned it with…
oakenshield1
  • 851
  • 1
  • 11
  • 26
12
votes
2 answers

How can I append a number to a string in Racket?

Python : xx = "p" + "y" + str(3) => xx == "py3" How can I get the same result using Racket? (string-append "racket" (number->string 5) " ") Is there another way in Racket, similar to the Python example above, to append a number to a string?
book-life
  • 149
  • 1
  • 5
12
votes
7 answers

Why is StringBuilder slower than string concatenation?

Why is StringBuilder slower when compared to + concatenation? StringBuilder was meant to avoid extra object creation, but why does it penalize performance? static void Main(string[] args) { int max = 1000000; for (int times…
Junior Mayhé
  • 16,144
  • 26
  • 115
  • 161
12
votes
2 answers

How much does Java optimize string concatenation with +?

I know that in more recent Java versions string concatenation String test = one + "two"+ three; Will get optimized to use a StringBuilder. However will a new StringBuilder be generated each time it hits this line or will a single Thread Local…
Tim B
  • 40,716
  • 16
  • 83
  • 128
12
votes
4 answers

paste grid -- expand.grid for string concatenation

If we want to get all combinations of two vectors, we can use rep/recycling rules: x <- 1:4 y <- 1:2 cbind(rep(x, each = length(y)), rep(y, length(x))) # [,1] [,2] # [1,] 1 1 # [2,] 1 2 # [3,] 2 1 # [4,] 2 2 # [5,] 3…
MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
12
votes
4 answers

stringByAppendingFormat not working

I have an NSString and fail to apply the following statement: NSString *myString = @"some text"; [myString stringByAppendingFormat:@"some text = %d", 3]; no log or error, the string just doesn't get changed. I already tried with NSString (as…
user306766