append a string to the end of another string in swift

To append a string at the end of another string in Swift, you can use the + operator or the += operator. Here's an example:

main.swift
var str1 = "Hello"
let str2 = " World"
str1 += str2
print(str1)  // Output: "Hello World"
90 chars
5 lines

In this example, we used the += operator to append str2 at the end of str1.

Alternatively, you can use the + operator to concatenate two strings and create a new string:

main.swift
let str1 = "Hello"
let str2 = " World"
let combinedStr = str1 + str2
print(combinedStr)  // Output: "Hello World"
114 chars
5 lines

In this example, we used the + operator to concatenate str1 and str2 into a new string combinedStr.

gistlibby LogSnag