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

Javascript console.log(object) vs. concatenating string

I'm running this in node.js: > x = { 'foo' : 'bar' } { foo: 'bar' } > console.log(x) { foo: 'bar' } undefined > console.log("hmm: " + x) hmm: [object Object] undefined What I don't understand is why console.log(x) "pretty-prints" the object,…
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
46
votes
4 answers

Is string concatenation in scala as costly as it is in Java?

In Java, it's a common best practice to do string concatenation with StringBuilder due to the poor performance of appending strings using the + operator. Is the same practice recommended for Scala or has the language improved on how java performs…
bionicseraph
  • 812
  • 1
  • 7
  • 10
45
votes
22 answers

How to concatenate int values in java?

I have the following values: int a=1; int b=0; int c=2; int d=2; int e=1; How do i concatenate these values so that i end up with a String that is 10221; please note that multiplying a by 10000, b by 1000.....and e by 1 will not working since b=0 …
Shamli
  • 467
  • 1
  • 4
  • 3
44
votes
4 answers

How do I concatenate 2 strings in NSIS

How do I concatenate 2 strings in NSIS?
DogDog
  • 4,820
  • 12
  • 44
  • 66
42
votes
3 answers

Why is the PHP string concatenation operator a dot (.)?

In PHP, the string operator dot (.) is used to concatenate strings. For example: $msg = "Hello there, " . $yourName; The dot operator always seems to confuse people (myself included) the first time they see it, especially since when you use it to…
Justin Ethier
  • 131,333
  • 52
  • 229
  • 284
40
votes
3 answers

Getting unicode string from its code - C#

I know following is the way to use unicode in C# string unicodeString = "\u0D15"; In my situation, I will not get the character code (0D15) at compile time. I get this from a XML file at runtime. I wonder how do I convert this code to unicode…
Navaneeth K N
  • 15,295
  • 38
  • 126
  • 184
39
votes
4 answers

Simple string concatenation in Objective C

I have an NSString named 'you' with value "This is a you string!". I want to concat "123" in 'you', how can I do it? I am using this code and it is giving an error. you=[you stringByAppendingString:@"123"];
Umair Khan Jadoon
  • 2,874
  • 11
  • 42
  • 63
39
votes
7 answers

How many String objects would be created when concatenating multiple Strings?

I was asked in an interview about the number of objects that will be created on the given problem: String str1 = "First"; String str2 = "Second"; String str3 = "Third"; String str4 = str1 + str2 + str3; I answered that there would be 6 objects…
39
votes
1 answer

What are the differences between concatenating strings with cat() and paste()?

What are the differences between concatenating strings with cat and paste? In particular, I have the following questions. Why does R not use the double quote (") when it prints the results of calling cat (but it uses quotes when using paste)? >…
Sam
  • 4,357
  • 6
  • 36
  • 60
38
votes
3 answers

Concatenate row-wise across specific columns of dataframe

I have a data frame with columns that, when concatenated (row-wise) as a string, would allow me to partition the data frame into a desired form. > str(data) 'data.frame': 680420 obs. of 10 variables: $ A : chr "2011-01-26"…
Jubbles
  • 4,450
  • 8
  • 35
  • 47
38
votes
5 answers

Memory usage of concatenating strings using interpolated vs "+" operator

I see the benefit of using interpolated strings, in terms of readability: string myString = $"Hello { person.FirstName } { person.LastName }!" over a concatenation done this way: string myString = "Hello " + person.FirstName + " " person.LastName +…
harveyAJ
  • 833
  • 1
  • 11
  • 26
36
votes
4 answers

Where is `+` implemented for Strings in the Java source code?

String is a special case in Java. It's a class, which I can examine in the source code, but it also has its own infix operator +, which seems to be syntactic sugar for StringBuilder. For example, "Hello " + yourName; could become new…
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
35
votes
4 answers

What is the difference between VBScript's + and & operator?

On every site that talks about VBScript, the '&' operator is listed as the string concatenation operator. However, in some code that I have recently inherited, I see the '+' operator being used and I am not seeing any errors as a result of this. Is…
Jeremy Cron
  • 2,404
  • 3
  • 25
  • 30
34
votes
2 answers

Can I concatenate strings in Elixir and use the pipe operator?

In Elixir, you can concatenate strings with the <> operator, like in "Hello" <> " " <> "World". You can also use the pipe operator |> to chain functions together. I'm trying to write the Elixir code to format the currency for an online game. def…
Kevin
  • 607
  • 1
  • 5
  • 15
33
votes
9 answers

String.format() vs "+" operator

What should be used for a basic string concatenation operation ? String randomString = "hello " + userName + " how are you" ? or String randomString = String.format("hello %s how are you ?",userName); I feel String.format() gives a better idea of…
Priyank Doshi
  • 12,895
  • 18
  • 59
  • 82