 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Swift Program to Convert an Set of String to Comma Separated String
Swift provide a inbuilt method named as joined() to convert a set of string to comma separated string. This function return the concatenated elements of the given sequence by inserting the given separator in between each element of the sequence.
Syntax
func joined(separator: sep)
Where the separator parameter contains a string or sequence, which is further used to insert between each element of the given sequence. This function returns a concatenated or joined sequence of elements.
Example
In the following code, we will create and initialize a set of strings. Then we join the elements of the set into a single string, which is separated by a comma using joined(separator: ",") function, and then display the output.
import Foundation import Glibc // Creating a set of string var myFavfruit : Set = ["Orange", "Sweet apple", "Apple", "Kiwi", "Mango", "Jackfruit"] // Joining elements of the set by comma let newString = myFavfruit.joined(separator: ",") print("New String is: ", newString)
Output
New String is: Apple,Orange,Kiwi,Jackfruit,Sweet apple,Mango
Conclusion
Therefore, this is how we can convert a set of string to comma-separated string. The joined (separator:_) method easily convert a set in a string by concatenating the elements of a set. Apart from comma, use can also use any separator according to your preference.
