Welcome to the Treehouse Community
Looking to learn something new?
Egor Bedunkevich643 Points
String Interpolation and Concatenation...
I just had a question that I was wondering about. I read an article about concatenation and they called it "string concatenation". I also know about String Interpolation. Is there such thing as Integer Concatenation or Interpolation? Furthermore, Does concatenation only work with strings or the same value? Can I please get a detailed response. (What is the difference between String Concatenation and concatenation) Is it the same thing?
Chris Shaw26,650 Points
// This will fail and cause a compiler error var myNumber = 10 var myString = "My pet chicken laid " + myNumber + " eggs" // This will work as we're using string interpolation var myNumber = 10 var myString = "My pet chicken laid \(myNumber) eggs"
Hope that helps.
Concatenation is the joining together of two values in a string format. For example '2'+'1' = 21 in a concatenation as it is treating the 2 and the 1 as strings and not integers. Without treating the 2 and 1 as strings 2+1 would equal 3. So to answer your question, yes they are the same thing.