Q:

Swift program to concatenate two strings

belongs to collection: Swift String Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

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 str1str2str3. 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

total answers (1)

Swift program to implement string interpolation... >>
<< Swift program to check a string is empty or not...