I know that if I want to convert an array of Int
s to a String
, I do this:
[0,1,1,0].map{"\($0)"}.reduce(""){$0+$1}
but I cannot figure out how would I convert an array of Int
s to a comma separated String
Given a Set of String, the task is to convert the Set to a comma separated String in Java. Approach: This can be achieved with the help of join() method of String as follows. Get the Set of String. Form a comma separated String from the Set of String using join() method by passing comma ', ' and the set as parameters.
The simplest way to convert an array to comma separated String is to create a StringBuilder, iterate through the array, and add each element of the array into StringBuilder after appending the comma.
To convert an array to a comma-separated string, call the join() method on the array, passing it a string containing a comma as a parameter. The join method returns a string containing all array elements joined by the provided separator.
How to get a comma separated string from an array in C#? We can get a comma-separated string from an array using String. Join() method. In the same way, we can get a comma-separated string from the integer array.
Well you can do it like :
let formattedArray = ([0,1,1,0].map{String($0)}).joined(separator: ",")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With