Append or Concatenate Strings in Swift
To concatenate two strings in Swift, use concatenate operator
+. The syntax to concatenate two strings is:
var str = str1 + str2
str2 are the two strings that we append. The concatenate operator
+ returns the resulting string and we are storing the resulting concatenated string in
In the following program, we have two strings in variables str1 and str2. These two strings are concatenated using Concatenation Operator
var str1 = "Hello" var str2 = " World!" var str = str1 + str2 print( str )
Example 2 – Concatenate Two or More Strings in Swift
You can concatenate more than two strings in a single statement as shown in the below example.
var str1 = "Swift" var str2 = "Tutorial" var str3 = "by" var str4 = "TutorialKart." //concatenate strings var str = str1 + " " + str2 + " " + str3 + " " + str4 print( str )
Swift Tutorial by TutorialKart.
In this Swift Tutorial, we have concatenated two or more strings using concatenation operator