C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Tip: Joined() can handle more than one character in the delimiter. But each delimiter is the same.
Swift program that uses join
// A string array of three elements.
let animals = ["cat", "dog", "bird"]
// Join the elements together with a comma delimiter.
let result = animals.joined(separator: ",")
print(result)
Output
cat,dog,bird
Tip: This is much simpler than a loop and string concats. And on large collections it may have a performance advantage.
Swift program that uses empty delimiter
// A string array.
let values = ["A", "B", "C", "D"]
// Join the elements with an empty delimiter.
let result = values.joined()
print(result)
// Display length of the result.
print(result.endIndex)
Output
ABCD
Index(_base: Swift.String.UnicodeScalarView.Index(_position: 4), _countUTF16: 0)