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"