So I have a nsmutablearray with a bunch of objects in it. I want to create a comma separated string of the id value of each object.
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.
Answer: Use the split() Method You can use the JavaScript split() method to split a string using a specific separator such as comma ( , ), space, etc. If separator is an empty string, the string is converted to an array of characters.
Use the String. split() method to convert a comma separated string to an array, e.g. const arr = str. split(',') . The split() method will split the string on each occurrence of a comma and will return an array containing the results.
Use the NSArray
instance method componentsJoinedByString:
.
In Objective-C:
- (NSString *)componentsJoinedByString:(NSString *)separator
In Swift:
func componentsJoinedByString(separator: String) -> String
Example:
In Objective-C:
NSString *joinedComponents = [array componentsJoinedByString:@","];
In Swift:
let joinedComponents = array.joined(seperator: ",")
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