Instance Method

joined(separator:)

Returns a new string by concatenating the elements of the sequence, adding the given separator between each element.

Declaration

func joined(separator: String = default) -> String

Parameters

separator

A string to insert between each of the elements in this sequence. The default separator is an empty string.

Return Value

A single, concatenated string.

Discussion

The following example shows how an array of strings can be joined to a single, comma-separated string:

let cast = ["Vivien", "Marlon", "Kim", "Karl"]
let list = cast.joined(separator: ", ")
print(list)
// Prints "Vivien, Marlon, Kim, Karl"

See Also

Splitting and Joining Elements

func split(separator: Self.Element, maxSplits: Int, omittingEmptySubsequences: Bool) -> [Self.SubSequence]

Returns the longest possible subsequences of the sequence, in order, around elements equal to the given element.

func joined() -> FlattenSequence<Self>

Returns the elements of this sequence of sequences, concatenated.

func joined<Separator>(separator: Separator) -> JoinedSequence<Self>

Returns the concatenated elements of this sequence of sequences, inserting the given separator between each element.