Advertisement

Swift program to concatenate two strings

Here, we are going to learn how to concatenate two strings in Swift programming language?
Submitted by Nidhi, on June 10, 2021

Problem Solution:

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.

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

Swift String Programs »



Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement



Copyright © 2024 www.includehelp.com. All rights reserved.