Instance Method


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


func joined(separator: String = default) -> String
Available when Element conforms to StringProtocol.



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.


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: ", ")
// 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.