Swift - Data Type String Concatenating

Introduction

In Swift, you can concatenate strings using the + operator:

Demo

var hello = "Hello"
var comma = ","
var world = "World"
var exclamation = "!"
var space = " "
var combinedStr = hello + comma + space + world + exclamation
print(combinedStr)  //Hello, World!

Result

You can use the addition assignment operator += to append a string to another string:

Demo

var hello = "Hello"
hello += ", World!"
print(hello)   //Hello, World!"

Result

Here, you are concatenating variables of the same type, which in this case is String.

Related Topic