Instance Method

append(_:)

Appends the given string to this string.

Declaration

mutating func append(_ other: String)

Parameters

other

Another string.

Discussion

The following example builds a customized greeting by using the append(_:) method:

var greeting = "Hello, "
if let name = getUserName() {
    greeting.append(name)
} else {
    greeting.append("friend")
}
print(greeting)
// Prints "Hello, friend"

See Also

Appending Strings and Characters

func append(Character)

Appends the given character to the string.

func append<S>(contentsOf: S)

Appends the characters in the given sequence to the string.

func append<S>(contentsOf: S)

Adds the elements of a sequence or collection to the end of this collection.

func reserveCapacity(Int)

Reserves enough space in the string’s underlying storage to store the specified number of ASCII characters.