Here, we will create two strings and then we will concatenate them using the "+" operator. After that, we will print the concatenated string on the console screen.
The source code to concatenate two strings is given below. The given program is compiled and executed successfully.
// Swift program to concatenate two strings
var str1 = "Hello "
var str2 = "World"
var str3 = ""
str3 = str1 + str2
print(str3)
Output:
Hello World
...Program finished with exit code 0
Press ENTER to exit console.
Explanation:
In the above program, we imported a package Swift to use the print() function using the below statement,
import Swift;
Here we created three string variables str1, str2, str3. Then we concatenated str1 and str2 using the "+" operator and assigned the result into the str3 variable. After that, we printed the str3 variable on the console screen.
Program/Source Code:
The source code to concatenate two strings is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we imported a package Swift to use the print() function using the below statement,
Here we created three string variables str1, str2, str3. Then we concatenated str1 and str2 using the "+" operator and assigned the result into the str3 variable. After that, we printed the str3 variable on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer