How to concatenate the strings in Swift
In this tutorial, we are going to learn about how to concatenate the strings in Swift.
Concatenation means the joining of two or more strings into a single string.
Concatenating Strings
To concatenate the two strings into a single string, we can use the addition operator +
operator in Swift.
let first = "john"
let second = "boss"
var name = first + second
print(name)
Output:
"johnboss"
Similarly, we can use the string interpolation syntax.
let first = "john"
let second = "boss"
var combined = "\(first) \(second)"
We can also append a string to an existing string using the +=
operator in Swift.
var name = "john"
name += "boss"
print(name)