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)

Adds an element to the end of the collection.

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.

Beta
func appending(String)

Returns a new string made by appending a given string to the String.

func appendingFormat(String, CVarArg...)

Returns a string made by appending to the String a string constructed from a given format string and the following arguments.

func padding(toLength: Int, withPad: String, startingAt: Int)

Returns a new string formed from the String by either removing characters from the end, or by appending as many occurrences as necessary of a given pad string.

func reserveCapacity(Int)

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