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



Hello World

...Program finished with exit code 0
Press ENTER to exit console.


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 »



Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.